APPNETOS is under active development This website and its documentation are being prepared for public launch. Content and features may change.
Select Theme
Loading

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

  1. The handler receives a normalized URI content item and extracts its document ID and data.
  2. It loads the active fragment document through the mapped context-specific collection.
  3. It reads and validates the document's nested content array.
  4. It creates a separate mapped Core\Content instance using Registry::getNew(Content::class).
  5. The nested controller initializes the fragment's content items in their defined order.
  6. 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.

Next Steps

Previous

Container

Explore Container

Next

Twig

Explore Twig