Guide 00 · Developer docs

Core dna for site builders

Read this guide first. Core dna is hosted, so there is nothing to install; your repository holds only templates and front-end assets; and a new kind of page starts in the admin, with a layout. In half a day, from what the platform is to a page you built, deployed and rendered in Smarty or Twig.

L0
Unit 04 · From URL to rendered page

The variables in every template

The platform variables every template receives, under the same names in Smarty ($_url) and Twig (_url): what each is for, which exist only on the public site, and which only when someone is signed in. Then the variables a controller adds, such as page and record.

Who this is for. Theme developers, as a reference to come back to. After this page you will know what a template can reach without anyone passing it in, and where to find the methods of each.

In every template

VariableWhat it isNotes
_currentSiteThe site and environment being served, with its id, hostnames and deployed commit (getLastVcsHash())
_currentUserWho is looking: isLoggedIn(), isFrontendUser(), isBackendUser(), getFullName(), getPerson()Present signed out too, when isLoggedIn() is false
_requestThe request: its path, parameters, cookies and languageEverything in it came from the visitor: escape it before printing
_responseThe response being built: redirects, cookies, caching
_urlBuilds URLs from module and route names, such as getPath('login')
_configReads site settings: get('Module.setting')
_siteDataThe site's own stored values, which editors change in the admin: get('key')
_messagesMessages for the visitor, by type: hasMessages(), getMessages()
_notificationsNotifications stored for the signed-in user
_stringString helpers
__Translations
_csrfTokenThe session's security token for forms and requests that change dataOnly when someone is signed in

On the public site only

VariableWhat it is
_menuMenus from the admin, by name: get('Header Menu')
_queryReads records the controller did not provide
_formsForms
_globalComponentsGlobal components, by identifier: get('identifier')
_imageImage helpers
_widgetsDeprecated: read records with _query instead
_searchSearch
_cartThe visitor's cart
_templateContextValues kept between the templates of one render, for example while a component or linked record is rendered: set() and get()
_inlineScriptNonceThe nonce every inline <script> must carry for the site's Content Security Policy

Templates that jobs render are the exception: they receive the job's own variables instead, hook, batch, event, site, runData, customData, siteData and query (and loopRecord and loopElement inside a loop), with no _url, _currentUser or any other variable above. Jobs and events lists them.

The same names in both engines

In Smarty the variables have a dollar sign, $_url; in Twig they do not, _url. In Twig they are globals, so they also reach inside a macro, which the controller's own variables do not unless you pass them in. The same few lines in each engine:

Template code
{if $_currentUser->isLoggedIn()}
  <a href="{$_url->getPath('logout')}">Sign out</a>
{else}
  <a href="{$_url->getPath('login')}">Sign in</a>
{/if}
{% if _currentUser.isLoggedIn() %}
  <a href="{{ _url.getPath('logout') }}">Sign out</a>
{% else %}
  <a href="{{ _url.getPath('login') }}">Sign in</a>
{% endif %}
Who is looking, on a cached page

Only a page rendered for a signed-out visitor is written to the page cache, and the cached copy is then sent to everyone, signed in or not. So markup that depends on _currentUser shows its signed-out version to signed-in visitors as well: Show logged-in state on a cached page shows the way round it.

And the controller's own

Besides the platform's variables, each controller adds its own. A show controller adds the record under its own name and as record: a page arrives as page and record. A component's template receives component. These names do not start with an underscore.

Global template variables covers the methods of each variable with examples, and the generated Templates reference lists what each default template receives.

Go deeper

Was this page helpful?

Your answer goes to the docs team.