Asset
Integrate CSS and JavaScript resources directly into URI-based content, without creating a dedicated App or template.
Purpose
Asset content provides a reusable way to attach stylesheets, JavaScript files, or inline code to a page through its URI content configuration. Each asset is represented by an active content document and is initialized as part of the normal content lifecycle.
Instead of producing markup, the asset handler registers resources with the APPNETOS
Core\Css and Core\Js controllers. These controllers manage the subsequent
resource output and processing.
Supported asset types
| Type | Source | Integration |
|---|---|---|
css |
CSS file path or source | Registers an external or file-based stylesheet using Core\Css::addFile().
|
js |
JavaScript file path or source | Registers a JavaScript resource using Core\Js::addFile(). |
inline-css |
CSS code stored in the document | Appends CSS code using Core\Css::append(). |
inline-js |
JavaScript code stored in the document | Appends JavaScript code using Core\Js::append(). |
File-based types require a non-empty source;
inline
types require non-empty content. Unknown types are rejected.
Integration possibilities
Assets can be included wherever URI content items are configured, making it possible to associate resources with a particular page or content composition. Common use cases include shared stylesheets, UI libraries, page-specific behavior, and small CSS or JavaScript additions that do not need a dedicated controller.
The asset document also exposes an attributes array. The handler reads and retains these
attributes, but the current registration methods only pass the source or inline content to the
CSS/JS
controller; they do not forward the attributes themselves.
Processing lifecycle
- The URI content item identifies an asset document by its
ObjectId. - The handler loads the active document from the context-specific asset collection.
- It reads the type, source, inline content, and attributes, then validates the asset type.
- It registers the resource with
Core\CssorCore\Js, depending on the type. - The respective resource controller handles subsequent output and any configured optimization.
For AJAX requests, the handler skips document loading and asset registration. Asset content does not provide a rendered view of its own.
Public API Reference
Core\Content\Asset
Class & Registry
Class:
Core\Content\Asset
Extends:
Core\Content\Asset\Base
use Core\Content\Asset;
use Core\Registry;
$asset = Registry::get(Asset::class);
| Method | Description |
|---|---|
init(array $item): void |
Initializes the content item, loads the active asset document, and registers its CSS or JavaScript resource for non-AJAX requests. |
getItem(): array |
Returns the normalized URI content item provided to the handler. |
getId(): ObjectId|null |
Returns the asset document identifier extracted from the content item. |
getData(): array |
Returns additional data associated with the URI content item. |
getDocument(): object|null |
Returns the loaded asset document, if available. |
getType(): string |
Returns the resolved type: css, js,
inline-css,
or
inline-js.
|
getPath(): string|null |
Returns the source value from the asset document, when present. |
getContent(): string|null |
Returns inline CSS or JavaScript content from the asset document, when present. |
getAttributes(): array |
Returns the attributes stored in the asset document; the handler does not pass them to the registration calls. |