Template
Reusable, data-driven Twig views rendered through the APPNETOS rendering engine without a dedicated application controller.
Purpose
Template content provides reusable UI building blocks backed by a template document. Each content item references an active document containing a template file and optional default data. APPNETOS renders the selected template with the effective data and passes the resulting view into the content rendering pipeline.
Unlike controller-based App content, Template content does not initialize its own application controller. Unlike Html content, it can evaluate Twig expressions, conditions and loops using the supplied data.
Template data and overrides
The template document defines the template path and may supply default values. The current URI
content
item can provide additional data or override values with matching keys. The merge uses PHP array_replace(),
so content item values take precedence.
$templateData = array_replace(
$documentData,
$contentItemData,
);
This makes it possible to reuse one Twig template across multiple URI content items with different data, without duplicating the template itself.
Rendering lifecycle
- Receive the normalized URI content item and extract its ID and data.
- Load the active template document from the collection mapped for the current context.
- Resolve the template file and merge document defaults with content item data.
- Render the template using
Core\Render::fetch(). - Expose the rendered HTML through
getView()for the subsequent content and response rendering stages.
AJAX requests skip template document loading, data preparation and view rendering. The shared handler does not manage app-specific JavaScript or CSS assets.
Public API Reference
Core\Content\Template
Class & Registry
Class:
Core\Content\Template
Extends:
Core\Content\Template\Base
use Core\Content\Template;
use Core\Registry;
$template = Registry::get(Template::class);
| Method | Description |
|---|---|
init(array $item): void |
Initializes the handler once, loads the active template document, prepares the merged data and renders the view for non-AJAX requests. |
getItem(): array |
Returns the normalized URI content item supplied to the handler. |
getId(): ObjectId|null |
Returns the content item's MongoDB ObjectId, or null if no valid ID was
supplied.
|
getData(): array |
Returns the content item's data before it is merged with the template document defaults. |
getDocument(): object|null |
Returns the loaded active template document, or null when none was
initialized.
|
getTemplate(): string |
Returns the resolved template file path or name from the template document. |
getTemplateData(): array |
Returns the effective data passed to Twig, with content item values overriding matching document defaults. |
getView(): string|null |
Returns the rendered template output, or null when no view was
produced.
|