| description |
|---|
Represents a single CMS item loaded from a Markdown file with front matter. Provides structured access to metadata, raw and rendered content, file paths, and relationships to other items. |
Creates a new CMS item.
- $cms (
ElementsCMS): The CMS instance. - $data (
array): The data for the CMS item.
Load a CMS item from a file.
- $cms (
ElementsCMS): The CMS instance. - $filepath (
string): Path to the file. - Returns:
ElementsCMSItem|null– Loaded item or null if not found.
Sets runtime options for the item.
- $options (
array): Option key/value pairs. - Returns:
$thisfor method chaining.
Gets an option value by key.
- $key (
string): Option name. - $default (
mixed): Default value if not found. - Returns: Mixed option value.
Returns the item’s slug (URL-friendly identifier).
Returns the item’s title.
Returns the item's date in the given format.
- $format (
string): Date format (default'F j, Y').
Returns the item's published date.
Returns the item's last modified date.
Checks if the item is marked as featured.
Returns the item's status (e.g., published/draft).
Returns the rendered HTML body content.
Returns the raw markdown body content.
Returns the item's image URL, if available.
Returns an excerpt of the body, limited to the specified word count.
Fetches a value from the item's metadata/front-matter.
- $key (
string): Meta key. - $default (
mixed): Default if key is missing.
Attach related data to the item (e.g., relations, computed properties).
Returns any value from the item data or metadata.
Allows dynamic method access to metadata fields.
Returns the full path to the file.
Returns the base filename (without extension).
Returns the item’s URL.
Returns the file's last modified date.
Returns all item data as an associative array.
Declare relations (one-to-one or one-to-many) to eager-load.
Declare one-to-one relations to eager-load.
Declare one-to-many relations to eager-load.
Loads all defined relations for the item.
$cms = new ElementsCMS(/* ... */);
$item = ElementsCMSItem::load($cms, 'posts/hello-world');
if ($item) {
echo $item->title(); // Item title
echo $item->body(); // Rendered body
echo $item->datePublished(); // Published date
$item->with('author', 'categories')->loadRelations();
}