Hand-written Includes in-depth notes
Component Registry component_library
No call site in this site yet
Return the component library registry as an array, for building a custom component index page or listing components grouped by slot.
component_library()
Pages Other
How do I read these repository paths?
All paths are relative to the site root. Open core/tpl_blocks.php at line 137 to see the definition of component_library(). 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: component_library
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.
3. Examples Every example can be copied as-is; the later ones are more advanced.
click the title to collapse / expand
Smallest inventory
The smallest inventory: name and identifier, both escaped.
<ul class="ry-component-index">
<?php foreach (component_library() as $c): ?>
<li><strong><?= e($c['name']) ?></strong> <code><?= e($c['code']) ?></code></li>
<?php endforeach; ?>
</ul>
Grouped by slot
An index grouped by slot, with the same code fallback the kernel uses for empty slots.
<?php
$groups = [];
foreach (component_library() as $c) {
$slot = $c['slot'] !== '' ? $c['slot'] : $c['code'];
$groups[$slot][] = $c;
}
?>
<div class="ry-wrap">
<?php foreach ($groups as $slot => $list): ?>
<h2 class="ry-slot__title"><?= e($slot) ?> (<?= count($list) ?>)</h2>
<ul class="ry-component-index">
<?php foreach ($list as $c): ?>
<li>
<strong><?= e($c['name']) ?></strong>
<code><?= e($c['code']) ?></code>
<span class="ry-muted"><?= e($c['description']) ?></span>
</li>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
</div>
Single-slot preview page
Inventory and render together: filter to one slot, render each match with its defaults, and keep an empty state.
<?php
/*
* Component preview page: render one slot only, so that several slots do not
* fight over the same render data. Each component renders with the default
* config from the registry, and overrides happen at the call site.
*/
$aSlot = 'page-content';
$total = 0;
?>
<div class="ry-wrap">
<?php foreach (component_library() as $c): ?>
<?php if ($c['slot'] !== $aSlot) { continue; } ?>
<?php $total++; ?>
<section class="ry-preview" data-component="<?= e($c['code']) ?>">
<?= render_component($c['code'], $c['default_config']) ?>
</section>
<?php endforeach; ?>
<?php if ($total === 0): ?>
<p class="ry-muted">No component is enabled for this slot yet.</p>
<?php endif; ?>
</div>
4. What it does / when to use it
Use it when a page has to know which components the site actually has: a custom component index page, an inventory by slot or category during development, or a snapshot of the registry before exporting an arrangement. It returns registry rows (code, name, name_en, category, slot, description, template_file, config_schema, default_config, is_active and more), active components only, ordered by category order, then component sort order, then code. Two limits: it renders no HTML at all, so drawing a component on a page is render_component()'s job, and it is not a layout decision, because which component appears on which page comes from the page arrangement.
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 |
|---|---|---|
| Other | Tool pages and everything else |
Used as needed on tool pages and anything else. You use it to: Use it when a page has to know which components the site actually has: a custom component index page, an inventory by sl |
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)
- Decide between an inventory and a render first. Listing, counting and auditing use
component_library(); drawing a component uses render_component().
- Choose the grouping before the loop. Grouping by
$c['slot'] matches components that can replace each other in one position, while grouping by $c['category'] mirrors the admin list. For rows with an empty slot, fall back to the code, exactly as the kernel slot mapping does.
- Treat every row as untrusted output and escape it:
e($c['name']) and e($c['description']). Both fields are editable in the admin, so customers can put quotes and angle brackets in them.
- To run a component with its own defaults on a preview page, pass the row value straight through:
render_component($c['code'], $c['default_config']). The registry already decoded the config into an array, so there is no JSON to unpack.
- Finish with an empty state. When nothing is returned, or every component is disabled, print a short message instead of leaving the page blank.
component_library(); drawing a component uses render_component().$c['slot'] matches components that can replace each other in one position, while grouping by $c['category'] mirrors the admin list. For rows with an empty slot, fall back to the code, exactly as the kernel slot mapping does.e($c['name']) and e($c['description']). Both fields are editable in the admin, so customers can put quotes and angle brackets in them.render_component($c['code'], $c['default_config']). The registry already decoded the config into an array, so there is no JSON to unpack.7. Common pitfalls
- Expecting the full list. Only rows with is_active are returned, so components disabled in the admin never appear. A count that does not match the admin list is that, not corrupt data.
- Using it as the render entry point. It returns config rows, so printing the result gives Array or nothing at all. Rendering goes through
render_component().
- Rendering every component in a loop with
render_component($c['code']) on a debug page. All of them share one render context, so they fight over the same data and overwrite each other styles, and the page turns slow and messy. Render the few you need and list the rest by name only.
- Editing the returned array to change a component default on the fly. It is a copy of the registry, nothing is saved and the change is gone on the next request. Override the config at the call site instead.
- Printing name or description without escaping. Both are admin-editable, and one component rename can break the page markup.
render_component().render_component($c['code']) on a debug page. All of them share one render context, so they fight over the same data and overwrite each other styles, and the page turns slow and messy. Render the few you need and list the rest by name only.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
No call site for this tag in this site templates yet.