Views & Widgets
CMS content is defined inline in view templates using three widget functions. Each call declares an editable region: the developer controls where it appears and what type it is; the admin controls the value.
cms_text()
Plain text, HTML-escaped on output. Optionally wrapped in a tag.
<?= cms_text('heading', 'Page Heading', 1, 'Default Title', 'h1') ?>
$slug | Unique identifier within the current context. Stored as a key in widgets.json. |
$label | Human-readable name shown in the admin sidebar. |
$pos | Integer controlling field order in the admin UI. |
$default | Fallback value when no content has been saved. |
$tag | CSS-selector-style wrapper tag. 'h1.hero#main' renders <h1 class="hero" id="main">. Empty string = no wrapper. |
The ->plain() method returns the escaped value without a wrapper, useful in <title> tags:
<?php $this->block('title', cms_text('heading', 'Heading', 1, 'Home')->plain()); ?>
cms_html()
Rich HTML content. Stored in a separate .html file (not JSON), making it easy for agents to edit and producing clean git diffs.
<?= cms_html('body', 'Body Content', 2, '<p>Default paragraph.</p>') ?>
The parameters are identical to cms_text(). In preview mode, the element gets contenteditable with a formatting toolbar.
cms_image()
Responsive image with optional aspect ratio cropping and srcset generation.
<?= cms_image('photo', 'Hero Photo', 1, '', '', 'A landscape photo', '16x9') ?>
$slug | Identifier, same as text/html widgets. |
$label | Admin UI label. |
$pos | Sort order. |
$default | Default image URL (empty = placeholder shown). |
$tag | Wrapper tag selector. |
$alt | Alt text for the <img>. |
$aspect | Aspect ratio for cropping, e.g. '16x9', '3x4', '1x1'. |
Tag selector syntax
The $tag parameter uses a CSS-selector-like syntax parsed into an HTML tag:
'h1' → <h1>...</h1>
'h1.blue' → <h1 class="blue">...</h1>
'div#hero.large' → <div id="hero" class="large">...</div>
'p.lead.italic' → <p class="lead italic">...</p>
'' → no wrapper (content rendered bare)
Tags, classes, and IDs can appear in any order: 'h1.blue#main.caps' works the same as 'h1#main.blue.caps'.