Fragment
Reusable content compositions that can be embedded across URIs and other content structures.
Purpose
A fragment groups multiple content items into a reusable content structure. Instead of defining the same collection of content items repeatedly, a URI or another content structure can reference a fragment document.
Fragments can combine supported content handlers, such as apps, HTML, templates and assets. Their nested content is initialized in its defined order, allowing recurring sections to be maintained centrally and included wherever needed.
Where fragments can be used
- Across URIs: reuse a common content composition on multiple pages.
- Inside containers: include a fragment as part of a larger reusable content group.
- Inside other content trees: compose reusable content structures without duplicating their definitions.
- Shared page sections: build recurring combinations of application components, static HTML and template-based content.
Fragments organize and expose content views; they do not themselves provide a dedicated Twig template or controller for the entire composition.
Initialization and rendering
- The handler receives a normalized URI content item and extracts its document ID and data.
- It loads the active fragment document through the mapped context-specific collection.
- It reads and validates the document's nested content array.
- It creates a separate mapped
Core\Contentinstance usingRegistry::getNew(Content::class). - The nested controller initializes the fragment's content items in their defined order.
- The resulting views can be retrieved through
getViews()and included in the wider rendering process.
The fragment handler does not directly render its own markup. Rendering is performed by its nested content handlers and the APPNETOS rendering layer.
Fragment and Container
Both content types group reusable content and initialize it through a separate
Core\Content
controller. A fragment additionally exposes the nested rendered views through its own
getViews() method.
The container handler explicitly rejects direct nested entries of type container. The
fragment handler does not implement the same explicit restriction. This does not by itself guarantee
that arbitrary recursive nesting is supported; recursive structures must still be evaluated against
the
nested content handlers.
Request behavior
For AJAX requests, the fragment handler skips document loading and nested content initialization.
Without
an initialized nested controller, getViews() returns an empty array.
Public API Reference
Core\Content\Fragment
Class & Registry
Class:
Core\Content\Fragment
Extends:
Core\Content\Fragment\Base
use Core\Content\Fragment;
use Core\Registry;
$fragment = Registry::get(Fragment::class);
| Method | Description |
|---|---|
init(array $item): void |
Initialize the fragment once, load its document and create its nested content controller for non-AJAX requests. |
getItem(): array |
Return the normalized content item supplied during initialization. |
getId(): ObjectId|null |
Return the fragment document identifier extracted from the content item. |
getData(): array |
Return the additional data associated with the content item. |
getDocument(): object|null |
Return the loaded fragment document, or null when unavailable. |
getContent(): Content|null |
Return the separate nested Core\Content controller, if initialized.
|
getViews(): array |
Return the nested controller's rendered views, or an empty array if no nested controller exists. |