App
Apps are reusable, controller-driven UI building blocks that combine application logic, templates, translations and optional JavaScript and CSS resources.
Purpose
An App is a self-contained content component initialized through a controller. It can provide its own controller structure, translations, templates, stylesheets and JavaScript files. APPNETOS initializes the component and makes its rendered view available to the content and rendering pipeline.
An App content component is distinct from the APPNETOS application that hosts it.
Controller and resources
The controller initializes the App and coordinates the data needed by its templates. Depending on the component, its directory may contain translations, Twig templates, JavaScript and CSS resources. The resulting view is returned to the rendering pipeline; it may also be represented by a View Slot.
Content Context Injection
App controllers can optionally implement Core\Content\ContentAwareInterface to
receive information about the content item that initialized them.
During regular App initialization, APPNETOS creates a new controller instance through the Registry.
If the controller implements the interface and the content item has a valid identifier, a
Core\Content\ContentContext is created and injected before the controller is invoked.
Implementation example
use Core\Content\ContentAwareInterface;
use Core\Content\ContentContext;
class MyApp extends Base implements ContentAwareInterface
{
protected ContentContext|null $contentContext = null;
public function setContentContext(ContentContext $context): void
{
$this->contentContext = $context;
}
}
Available context properties
| Property | Description |
|---|---|
type |
Normalized content type. |
id |
MongoDB identifier of the originating content item. |
data |
Content-specific runtime data. |
Content context injection is optional. Controllers that do not implement the interface continue to operate without changes.
Automatic context injection currently applies to regular App controller initialization. AJAX controller dispatch requires separate context resolution.
JavaScript and CSS delivery
APPNETOS handles App JavaScript and CSS resources that are not already served from the public directory according to the configured asset-cache settings.
| Asset cache | Behavior |
|---|---|
| Disabled | Non-public App JavaScript and CSS are included without caching at the end of the DOM. |
| Enabled | Resources are copied to the public directory using a unique hash-based filename, optionally minified when minification is enabled, and included in the document head. |
Minification is optional and depends on the active JavaScript and CSS configuration.
Public API Reference
Core\Content\App
Class & Registry
Class:
Core\Content\App
Extends:
Core\Content\App\Base
use Core\Content\App;
use Core\Registry;
$app = Registry::get(App::class);
| Method | Description |
|---|---|
public function getItem(): array |
Returns the content item used to initialize this App component. |
public function getId(): ObjectId|null |
Returns the content item's MongoDB object ID, if available. |
public function getData(): array |
Returns the content data associated with the App. |
public function getDocument(): object|null |
Returns the loaded App document, or null when none is available. |
public function getDirectory(): string|null |
Returns the resolved runtime directory of the App, if available. |
public function getController(): object|null |
Returns the initialized App controller, if available. |
public function getView(): string|ViewSlot|null |
Returns the App's rendered view, a View Slot, or null if no view is available. |