Capy-Bearer Documentation

component_render

lib call

Capy

function component_render(name : string, props : as any = {}, request : capture any) bool

Description

component_render() renders a component and writes its output straight into the current response. It returns true when it renders the component. It returns false when it cannot resolve the component.

This is the form to reach for in page layouts. component() opens a capture buffer, collects everything the component prints, and hands you a string; component_render() skips that buffer entirely. When you are only going to print the result anyway, component_render("card") does less work than print(component("card")).

Use a capturing call instead when you need the output as a value — to measure it, wrap it, store it, or decide whether to emit it at all.

Name resolution, :HANDLER suffixes, props arguments, and ONCE behavior match component(). That page documents the rules.

Parameters

name : a component path, optionally followed by :HANDLER

props : optional input, received through the component's props parameter

request : the caller's request, captured when omitted

Errors

An unresolvable component does not raise an error. Bearer sets the response status to 500 and returns false. Rendering continues.

Example

Capy

component_render("/doc/examples/card.capy:CARD", title: "Release notes")

Output

<article>Release notes</article>

Example

Capy

print("<main>")
component_render("/doc/examples/card.capy:CARD", title: "First")
component_render("/doc/examples/card.capy:CARD", title: "Second")
print("</main>", "\n")

Output

<main><article>First</article><article>Second</article></main>

Example

Capy

var rows := ["Ada", "Grace", "Katherine"]
for row := rows
{
	component_render("/doc/examples/card.capy:CARD", title: row)
}
print("\n")

Output

<article>Ada</article><article>Grace</article><article>Katherine</article>