Hand-written Includes in-depth notes
Render Component render_component
Used in page templates
Renders any component by code and lets you pass data into it (lower level than content_block).
render_component($code, array $config = [], array $data = [])
Pages Home List pages Detail pages Single pages
How do I read these repository paths?
All paths are relative to the site root. Open core/tpl_blocks.php at line 129 to see the definition of render_component(). The "core method" is what the tag actually forwards to: a template writes content_list(...) and the core runs Tpl::contentList(...).
1. Fill in parameters, get the code Edit any field and the result below updates instantly; press Copy and paste it into a template. It also works without JavaScript: press Generate and the server recomputes it.
click the title to collapse / expand
Now generating: render_component
This is the real rendering of the page (real header, container, this tag output, real footer). It reloads when you change a parameter.
Refreshing…
This is the server-computed default; it updates as you edit any parameter and the preview on the right is re-rendered too. It also works without JavaScript: fill the form and press Generate.
2. Full parameter table 2 parameters, one per row; scroll sideways on narrow screens.
click the title to collapse / expand
| Parameter | Type | Default | Description |
|---|---|---|---|
code |
string |
required / as needed | Component code, must exist and be active; otherwise output is empty. |
data |
array |
[] | Extra template variables, the third argument; put second and the component loses them. |
3. Examples Every example can be copied as-is; the later ones are more advanced.
click the title to collapse / expand
Minimal, one card per row
Keep the second argument as an empty array and put the row in the third: the only correct way to feed a card component.
<?php foreach (content_list(['model' => 'product', 'limit' => 6]) as $item): ?>
<?= render_component('product-card', [], ['item' => $item]) ?>
<?php endforeach; ?>
A block component, configuration only
A block component fetches its own data from its configuration, so the second argument is all it needs.
<section class="ry-section">
<?= render_component('home-news', ['limit' => 4, 'title' => 'Latest news']) ?>
</section>
Handing page data to a list component
The third argument passes data explicitly; the component renders the list only, so the template prints the pager itself.
<?php $q = content_query([
'model' => 'news',
'page' => max(1, (int)($current_page ?? 1)),
'page_size' => 10,
]); ?>
<?= render_component('list-content', [], ['items' => $q['items']]) ?>
<?= pager($q['paginator']) ?>
4. What it does / when to use it
Use it to render any registered component from a template. It goes through the component registry, so it checks that the component exists and is enabled, fills in default configuration and casts values by the config schema, fires plugin hooks, and then renders the component file. Passing a batch of rows to a card component one by one, such as product-card in a list, is the classic case. When you want fetch-and-render in one step, content_block is shorter, and pure layout pieces such as containers, sections, and footer blocks should use their own tags rather than being wrapped as components.
product-card in a list, is the classic case. When you want fetch-and-render in one step, content_block is shorter, and pure layout pieces such as containers, sections, and footer blocks should use their own tags rather than being wrapped as components.5. Which pages it belongs on This is the question clients actually ask: "I am building the home page / a list page / a detail page — which tags do I use?"
click the title to collapse / expand
| Page | What that page is | What this tag does there |
|---|---|---|
| Home | Home page: hero, category blocks, latest content |
On the home page it usually sits in the hero, a category block, or a latest/featured section. You use it to: Use it to render any registered component from a template |
| List pages | Category list pages: listing, filters, pagination |
On a list page it lives in the list container or right next to the pagination bar. You use it to: Use it to render any registered component from a template |
| Detail pages | Content detail pages: body, specs, related items |
On a detail page it goes in the body area or in the related-items sidebar. You use it to: Use it to render any registered component from a template |
| Single pages | One-off pages such as About or Contact |
On a single page (About, Contact) it sits inside the content block. You use it to: Use it to render any registered component from a template |
Clicking a page name jumps to every tag for that page in the reference (the "By page" filter there). This page always shows everything about the tag, whatever that filter is set to.
6. How to use it (step by step)
- Confirm the component code first. The identifier registered in the component library (
product-card, home-news, and so on) is the first argument. A wrong code throws nothing: in debug mode it leaves an HTML comment, and in production it renders nothing.
- Pass configuration overrides as the second argument, for example
['layout' => 'list'] or ['limit' => 4]. Options you leave out are filled from the component defaults, and values are cast by the config schema, so numeric strings become numbers, switches become booleans, and an invalid select value falls back to the default.
- Pass extra variables the component needs as the third argument, for example
['item' => $item], which is available inside the component as $item. Without it the component uses the current page context, which is why block components usually need only the first two arguments.
- Prepare the data you want to render. In a list template, loop over the result of
content_list or content_query and hand one row at a time to the card component; inside the component template that row is the row variable.
- Reach for it when you need registry validation, default configuration, and plugin hooks. For a plain fetch-and-render call,
content_block is shorter.
product-card, home-news, and so on) is the first argument. A wrong code throws nothing: in debug mode it leaves an HTML comment, and in production it renders nothing.['layout' => 'list'] or ['limit' => 4]. Options you leave out are filled from the component defaults, and values are cast by the config schema, so numeric strings become numbers, switches become booleans, and an invalid select value falls back to the default.['item' => $item], which is available inside the component as $item. Without it the component uses the current page context, which is why block components usually need only the first two arguments.content_list or content_query and hand one row at a time to the card component; inside the component template that row is the row variable.content_block is shorter.7. Common pitfalls
- Putting row data in the second argument: in
render_component('product-card', ['item' => $item]) the item key becomes component configuration, while the card component reads the variable $item, so every row renders empty. Row data belongs in the third argument, and when you have no configuration, pass an empty [] to hold the position.
- A component that was disabled in the admin, or a code that is not in the registry, returns nothing silently. In debug mode the page carries a comment saying the component is missing or inactive; in production there is nothing at all, so turn debug mode on before hunting for a missing block.
- When a component throws, the page does not break: the error is written to the log and an empty string is returned, with a comment in debug mode. If a block vanishes, read the component render failure entry in the log rather than staring at the template.
- Passing query options as configuration. Keys such as
model and limit only fetch data in content_block; here they do not query anything and simply sit in the configuration array.
Note from the reference table The old example passes data as the second argument, which is really the config slot; variables such as $item must go third: render_component('product-card', [], ['item' => $item]).
render_component('product-card', ['item' => $item]) the item key becomes component configuration, while the card component reads the variable $item, so every row renders empty. Row data belongs in the third argument, and when you have no configuration, pass an empty [] to hold the position.model and limit only fetch data in content_block; here they do not query anything and simply sit in the configuration array.$item must go third: render_component('product-card', [], ['item' => $item]).8. Real rendered output This section was rendered once on the server with this site real data; it is not a mock-up.
click the title to collapse / expand
It outputs a whole page region (this site header / footer / a full layout section, or it decides what to render from the current page data). Inside this small box it would just splice another page skeleton into this one: you would not see its real effect, and it would wreck this page. Copy it into your template instead.
Loading the code…
9. Where it already appears in your templates Grouped by components / page templates / template packs; the data comes from a script scan.
click the title to collapse / expand
Page templates 1 files / 11 calls
-
templates/default/home.php×11 lines 28, 39, 40, 41, 42, 43…
Template packs 1 files / 7 calls
-
templates/official/home.php×7 lines 39, 40, 41, 42, 43, 44…
Click "See this code + preview": the left shows the real code around that call site (±12 lines, call line highlighted) and the right renders a real page preview with the current parameters.
Common combinations (generated from your real templates)
- The page template hosting this tag is home
templates/default/home.php
templates/default/home.php
At a glance
render_component
Home / List pages / Detail pages / Single pages