uce/site/doc/pages/component_render.txt

37 lines
1.2 KiB
Plaintext

:sig
void component_render(String name, [DTree props], [Request& context])
:see
>ob
component
component_exists
component_resolve
1_COMPONENT
:content
Renders another `.uce` file as a component and writes the result directly to the current output buffer.
This is the direct-output counterpart to `component()`.
Component props are passed through `context.props`, and `name:COMPONENTFUNC` may be used to select a named handler exported by `COMPONENT:COMPONENTFUNC(Request& context)`.
When `name` starts with `:`, the runtime resolves that named handler against the current `.uce` file.
If the target file defines `ONCE(Request& context)`, that hook runs once per request before the file's first component or render entrypoint.
Use `component_render()` when you want to write component output directly from C++ code instead of capturing it as a `String`.
## Example
```cpp
DTree props;
props["body"] = "Hello";
component_render("components/card:BODY", props, context);
```
## Related Concepts
- PHP: rendering a partial directly into the current output buffer rather than returning a string
- JavaScript / Node.js: direct `res.write()`-style partial rendering or imperative component mount helpers