Docs: Head, assets and views
Head, assets and views
Dates, the head and the files around a view: date, seo, icons, design, assets, asset, assetVersion, pushAsset, option, render and component.
The examples use the $esc shortcut from the overview.
Formatting #
date($value, $style = 'date') #
A stored time (a Y-m-d H:i:s UTC string, or a Unix timestamp) in the site's time zone and the content language (E). A value or style it does not know gives an empty string. The time zone is the site's (Settings ▸ General; UTC when unset), and the month names follow the content language.
Styles: date (10 October 2026), short (10 Oct 2026), datetime, time, month (October 2026) and iso for <time datetime>. There are no "3 days ago" styles, because a cached page would keep saying them.
<time datetime="<?= $this->date($p['published'], 'iso') ?>"><?= $this->date($p['published'], 'short') ?></time>
timeTag($value, $style = 'date', $attrs = []) #
New in 1.19.0. The same date as date(), as <time datetime="2026-10-10T08:30:00Z" data-relative>10 October 2026</time> (M). It gives an empty string for a value or style it does not know. The full date is always the text and the UTC moment is always in datetime. While the site owner has Relative dates on under Settings ▸ General, core's script rewrites the text in the browser and puts the full date in data-tooltip (never title), so a cached page never keeps a stale "3 days ago". Since 1.21.0 the setting "Recent dates read as" picks the style: ago (the default, "3 days ago") or clock ("yesterday, 15:14"). The clock style says "just now", then minutes and hours for today, then yesterday, the weekday and the date, each with the time in the Regional format's clock; a time in the future keeps its full date. The words follow the language's own case, so "yesterday" may start in lower case. Core adds the tooltip script and one <meta name="cms-dates"> before the first </head>, and it also rewrites a <time data-relative> your script adds after the page has loaded. $attrs adds attributes, such as ['class' => 'meta']; datetime and data-relative cannot be overridden. A theme that writes its own <time> should carry the same data-relative and a UTC datetime to take part.
<?= $this->timeTag($p['published'], 'short', ['class' => 'meta']) ?>
Numbers #
number($value, $decimals = 0) #
New in 1.19.0. A count with the grouping and decimal separators of Settings ▸ System ▸ Regional format, or of the content language while that follows the language (P): 1,234, 1.234 or 1 234. Write every count through it, not through PHP's number_format(), which is English whatever the site's language.
<span class="votes"><?= $esc($this->number($item['votes'])) ?></span>
The head and the contracts #
seo(), icons(), design() #
The head block, the icon set and the design-token block (M). design() gives an empty string when the theme declares no tokens. Each claims its contract; leave one out and core adds it for you. Calling one without printing it (<?php $this->seo(); ?>) claims it for a theme that does the job itself. Pass the settings table to seo(?array $settings = null) when your header already loaded it. A view adds what core cannot know by passing seo to the header component.
<head>
<?= $this->seo() ?>
<?= $this->icons() ?>
<link rel="stylesheet" href="<?= $esc($this->asset('main.css') . '?v=' . $this->assetVersion('main.css')) ?>">
<?= $this->design() ?>
</head>
siteIcon($settings = null) #
New in 1.19.0. The site icon from Settings ▸ General as head tags (M): a 32 px icon and a 180 px apple-touch-icon made from a PNG or JPEG, or the SVG itself for an SVG; an empty string when no icon is set. Calling it claims the icon, so seo() does not draw it again.
<?= $this->siteIcon() ?>
providesContainer() #
Claims that your <main> is already width-limited, centred and guttered.
<?php $this->providesContainer(); ?>
<main id="main" class="site-main">
The cookie banner, the cookie link, the asset channel, the language switcher and <html lang> are claimed the same way. See Sign-in, forms and consent for the cookie ones.
Assets #
asset($path) #
A file in your theme's assets/ as a URL (P), without a version stamp. It leaves the stamp off on purpose: a font URL must match the url() inside your CSS byte for byte, or the browser fetches it twice.
assetVersion($path) #
New in 1.18.0. A ?v= value for the same file that changes whenever the file does (its modification time and size). For a missing file you get CMS_VERSION. It is safe to print as it is. Add it yourself where it matters:
<link rel="stylesheet" href="<?= $esc($this->asset('main.css') . '?v=' . $this->assetVersion('main.css')) ?>">
Version your stylesheet and script URLs. Without a version, a visitor who cached your stylesheet under the previous release keeps it after an update. Your markup changes, your CSS does not, and the site looks broken for returning visitors only.
A ?v= that does not move with the file is now worse than none. Since 1.18.0 the root .htaccess tells browsers to keep any static file with ?v= in its address for a week, without asking again. CMS_VERSION stays the same while you edit a theme between releases, so CSS edited under an unchanged ?v= is served stale for up to a week. Use assetVersion(), not CMS_VERSION or a number of your own.
assets($kind) #
The stylesheets ('css') or scripts ('js') that modules pushed for this page, in push order (P). Calling it claims the asset channel.
<?php foreach ($this->assets('js') as $pushedJs): ?>
<script type="module" src="<?= $esc($pushedJs) ?>"></script>
<?php endforeach; ?>
pushAsset($kind, $url) #
Adds one URL to that list, once. It is a module's or a component's call. The default theme pushes its own account-menu script from the header, and the footer prints the channel.
<?php $this->pushAsset('js', $this->asset('account-menu.js') . '?v=' . $this->assetVersion('account-menu.js')); ?>
Keep script in files: a file is cached with the page's other assets, and the admin panel's own content security policy already refuses inline script.
Theme options #
option($key, $default = null) #
One of the theme's own options (P): the saved value, else the default in theme.json, else $default. A choice, a layout or a font is judged again against your declaration. Text is text, so escape it, a judged choice included. While a reviewer previews a design draft, the draft's value answers.
<?php $header_layout = (string) $this->option('header_layout', 'split'); ?>
<header class="site-header header-<?= $esc($header_layout) ?>">
Views #
render($view, $data = []) and component($name, $data = []) #
Include a view or a component of your theme. If you have none, core uses an enabled module's, and then core's own as the floor. render() returns true when it found one. Each key of $data becomes a variable in the file. A module may hand a component ready data of its own, and a key the caller passed wins. The front controller calls render() for you. A theme calls component().
<?php $this->component('header', ['seo' => ['type' => 'article', 'published_time' => $iso]]); ?>
<?php $this->component('footer'); ?>
pageHeadDefault($data = null) and slot($name, $data = []) #
New in 1.19.0. A view that draws a heading calls $this->component('page-head', [...]) with a context such as blog.post, an already escaped title and, where the page has them, more. Core's page-head component calls pageHeadDefault(), which draws the page head the module that owns the context ships, or a plain <h1> of title (E). With no argument it uses the data of the page head being drawn. To restyle some contexts, ship your own components/page-head.php and hand the rest back with one line:
<?php if ($context === 'blog.post'): ?>
<header class="my-post-head"><h1><?= $title ?></h1></header>
<?php else: $this->pageHeadDefault(); endif; ?>
slot() is a named place in a view, filled by a file named after it: your theme's components/slots/<name>.php, else an enabled module's, else nothing is drawn. The Blog post view offers blog.post.after_head and blog.post.after_body, each given ['post' => ...], the escaped post.
Core and the Blog ship small components you can restyle by shipping a file of the same name in components/: page-head, page-breadcrumbs, page-updated, page-children, pager, person-avatar (since 1.19.2, in Forums, comments and the Tracker), blog-card, blog-category-chip and blog-category-bar. The full table is in Themes.
What the module views hand over, ready #
A module's view or component that you override receives its data already decided. Everything that was there stays (can_edit and can_delete included). These keys are new in 1.18.0, and a view may print them without a test of its own.
- Forums topic page:
reply_state(open, or the reason a reply is closed) andreply_notice(the language key to print when it is not open, elsenull). The topic'surlandmod_url. Each post'sauthor_name(empty for a former member),permalinkandpurge_url. - Comments thread: each item's
can_editandcan_delete. They decide nothing. Print the controls withactions('comments.comment', $item). - Blog:
blog_title,blog_url, and on a postpost_url. The Blog's category page also getscategory_url,feed_urlandcategory_bar(nullwhen fewer than two categories hold a live post). The listing'spagerisnullon one page, else{page, pages, newer_url, older_url}with anullwhere there is no such page. Each listing row in$postsalso carriestag_list(its tags, raw) andpost_url. - Feedback's ticket thread:
ticket(with its ready labels,can_replyandcan_closeto draw its two forms, andtracker_links: the tracker items staff made from the ticket, as{ref, title, url}, raw, only the ones a guest may see,[]when none),replies, andportal(open,can_create,csrf,endpoint,title,flash). The portal form's data arrives through the module, so aticket-formcomponent reads no setting. - Tracker views: see Tracker.
New in 1.20.0 #
dateLocale(): the locale tag a script formats this page's times with, carrying the Regional format's clock.emojiWords(): the emoji picker's words in the page's language.- Two design tokens:
--cms-danger, for a leaving or destructive action such as Sign out, and--cms-sticky-top, the height of a sticky header (0px when unset), so a sticky side menu stops under it.
New in 1.21.0 #
- Design tokens:
--cms-online(the online dot),--cms-accent(the Share buttons),--fx-award-tip-*(the award tooltip) and--cms-target-bg, the background of a community rule you linked to, used by.cms-rules__rule:targetwithanimation: var(--core-target-fade). - The slot
account-profile-extra. Forums fills it with the signature field. A theme file that replaces the slot must draw it too, or members cannot edit their signature. - Components:
share,blog-discussion,rules-accept,page-policy,message-envelope,restriction-notice,pictures,pictures-fieldandforums-awards.