Skip to content

Templates and sections

Templates are PHP files with one variable, $v. That is the page being drawn.

Templates

  • Escape every value from content with $v::e(). The CMS sends some fields as HTML. Those come out as they are, with their shortcodes drawn. Use $v->blocks(...) and $v->html($data) for them.
  • The head. A layout writes only the charset, the viewport and the title. Then it writes <?= $v->head() ?>. The engine puts everything else in its place, such as hints, styles, meta tags and structured data. It checks every page, and reports a wrong order to the CMS.
  • Which template. A page uses its template from the CMS, as templates/<template key>.php. Otherwise, it uses default.php. A page with the block of a module uses module-<name>.php.
  • Copy from base. The base theme has defaults that are made to be copied and changed:
    • header.php has the logo, the main menu with its button, and the light/dark switch;
    • footer.php;
    • blog.php has the date, authors, image, contents and share links;
    • list-item.php.

Blocks and sections

  • Sections are the own types of the CMS: hero, text, feature, media and banner. Draw them with the helpers: open, text, rich, buttons, image and close. Then design choices, classes and image priority work the same everywhere.
  • For an existing design, map the parts onto your CSS in theme.php, under sections. That is better than templates of your own.
  • data.anchor is the id of the section. So a menu can link to /#pricing.
  • data.title_html is the title with emphasis. It holds only <em> and <br>.
  • data.illustration names a picture in illustrations/<key>.php. It is drawn where an image would be. Its texts are in the strings of the theme, so they follow the language of the page.
  • Blocks of other types are drawn by blocks/<type>.php. The one of the theme comes first, then the one of the parent.

Lists of records

A page can list records, such as products, reviews or vacancies. It draws them with <?= $v->records() ?>. The own page of a record draws its fields with <?= $v->recordDetails() ?>.

  • To draw your own, use templates/list-<module>.php, list-item-<module>.php, list-facet.php and record.php. list-facet.php is one filter group.
  • $v->fieldValue(), $v->money(), $v->dateText() and $v->stars() format values.
  • Filters are one plain GET form, which works without a script. A script makes it live, and keeps the address in step. A filtered view is noindex, follow, with the canonical of the page without filters.
  • How lists look is set per module in theme.php, under lists. '*' means every module. The display settings of the module in the CMS override it:
Key Values Default
filters start, end, top, none start
filters_mobile dialog, inline dialog
sort_control toolbar, facets, both, none toolbar
facet_show the options shown before "show all" (0 means all) 8
facet_search a search field from this many options (0 means never) 12
  • Pages per year and per tag are looked up like pages. Each has its own title, canonical and place in the sitemap.

A card in a list is often one link as a whole: a post, a product or a person. The engine has a pattern for that, so the whole card is clickable and a keyboard still stops once per card.

  1. Give the card the class lb-stretch-box.
  2. Give its real link the attribute data-stretched-link. That is the link in the heading, else the card's only button.
  3. End the card with <?= $v->stretch($href) ?>, with the same address as the real link.
PHP
<article class="card lb-stretch-box">
    <h3><a href="<?= $v->e($url) ?>" data-stretched-link><?= $v->e($title) ?></a></h3>
    <p><?= $v->e($intro) ?></p>
    <?= $v->stretch($url) ?>
</article>
  • $v->stretch() adds an empty link over the whole card. It is out of the tab order and hidden from screen readers, so only the real link is read and focused.
  • Other links and buttons in the card stay above it and keep working.
  • The focus ring of the real link shows around the whole card.
  • Use an attribute, not a class, on the real link. Many themes underline a:not([class]), and a class would take that away.
  • View::navToggle($panelId) gives the button that opens a menu on a small screen. The panel is a native popover, so it needs no script.
  • $v->menuPanel($item) draws what folds out of a menu item. That is the content blocks, or the grid of a panel.
  • The languages in the header come with their own names, lang and hreflang. They link to the translation of the page, or to the home page of that language.

Structured data

The CMS puts structured data in the head of every page that may be indexed. That is Organization, WebSite and BreadcrumbList, and per type BlogPosting, Event, Product and FAQPage. To switch a type off, set it in theme.php, such as 'json_ld' => ['Product' => false].

Also called: theme templates, view layer, partials, page templates.

Last changed