Views on tags: which pages a theme file can replace
Any page of the site can be replaced with a tag file without PHP: which files the theme understands, how to make your own 404 and what is available in the core views.
Any view of the site (home page, sign-in, registration, search, account, a page) can be replaced with a tag file. It is plain HTML markup into which tags {name}, conditions [if:name]…[/if] and loops [each:list]…[/each] are inserted (the common tag language, the same as in “News → Entry templates”). It is a safe analogue of template files in other engines: you cannot write PHP in a tag file. The page frame (header, menu, sidebar, footer) is described in the article “The site’s main template on tags”, and so are the common tags of any page.
How to turn it on
In your theme put a file at the view’s path ending in .tpl.html instead of .php:
| What you replace | File in the theme |
|---|---|
| the main markup (header, places, content, footer) | themes/NAME/views/layouts/main.tpl.html |
| a site page | themes/NAME/views/pages/show.tpl.html |
| sign-in | themes/NAME/views/auth/login.tpl.html |
| registration, password recovery, reset, second factor, email confirmation, rules | auth/register.tpl.html, auth/forgot.tpl.html, auth/reset.tpl.html, auth/two-factor.tpl.html, auth/verify.tpl.html, auth/rules.tpl.html |
| search | search.tpl.html |
| account, security, sessions, privacy | auth/profile.tpl.html, auth/profile-security.tpl.html, auth/profile-sessions.tpl.html, auth/profile-privacy.tpl.html |
| public profile | auth/public-profile.tpl.html |
Your own 404 and any page as a theme file
Put themes/THEME/views/errors/404.tpl.html (or create it with the theme:file command, see below), write markup with the tags {status}, {message}, {search}, {home} — and the 404 page becomes yours. Any file from the list is replaced the same way: the footer partials/footer.tpl.html, the sidebar partials/sidebar.tpl.html, the full news item news/show.tpl.html.
Which files can be replaced and how to create them
The full list of files a theme can replace with its own (now 58: frame, header, footer, sidebar, card, news, comments, messages, forum, shop, events, gallery, polls, search, sign-in, account, error pages) is shown by the command:
php nex1on theme:files my-site“есть” (present) means the file already lies in your theme, “—” means the engine draws the page. To start from a ready one, create the file from a template (the name can be written as errors/404, errors-404, news::show or a full path):
php nex1on theme:file my-site errors/404The file appears at themes/my-site/views/errors/404.tpl.html with default tags: edit it in any editor, the page picks up the changes at once, without the admin. The command does not overwrite an existing file (--force overwrites).
If the tag file is missing or broken (for example, an unclosed block), the ordinary view works and the page does not break. A tag file in the theme’s common folder outranks a module’s view, just like a PHP file.
View data: conditions and loops
Besides the common tags, the file has the data the view received from the engine: {name}, {a.b}, [each:list] with {item}, {item.key}, {index}, the conditions [if:name], [if:name=value], [ifnot:name], and the limit=N option. Secrets (form protection keys, passwords, tokens, sessions) and objects are not given through tags.
Core views on tags
| View | What is available (besides the common tags) |
|---|---|
auth/login | {form} — the ready sign-in form; words {t.eyebrow}, {t.title}, {t.lead}, {t.forgot}, {t.no_account}, {t.submit} and others; {forgot_url}, {register_url}; the condition [if:can_register] |
auth/register | {form}, words {t.…} (prefix auth.register), {forgot_url} |
auth/forgot, auth/reset, auth/two-factor, auth/verify, auth/rules | each has {form} and words {t.…} (prefixes auth.forgot, auth.reset, auth.2fa, auth.verify, auth.rules) |
search | {form} (the search box), {query}, [each:results] ({item.title}, {item.url}, {item.excerpt}…), [each:popular], {found.*}, [if:tooShort], {minimum}, words {t.…} (search.*) |
auth/profile, auth/profile-security, auth/profile-sessions, auth/profile-privacy | {form} (and {form:2}, {form:3} — the view’s other forms in order), {identity} (the account header), {profile_nav} (the account menu), words {t.…} (profile.*) |
auth/public-profile | {identity} and the profile data |
pages/show | {title}, {page.title}, {page.excerpt}, {page.body} (the page text, engine markup), {cover}, [each:trail], [each:children], [each:siblings] |