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 01 · What you are building on
Smarty and Twig are peers
What you are building onPage 3 of 28Updated
Core dna renders server-side templates in Smarty or Twig. Each site uses one, and both receive the same variables and the same records under the same names. What is the same, the handful of differences, and why every template example in these docs is given in both.
Who this is for. Theme developers, and anyone who will copy a template example from these docs. After this page you will know that neither engine is the default option and the other a fallback, what the choice of engine changes, and what it leaves alone.
One engine per site
A site renders all its templates with one engine, chosen by the site setting Globals.template.engine: Smarty unless the site is set to Twig. It is not among the settings an administrator can change in the admin, so ask Core dna when a site needs the other engine. Templates rendered in the background, such as those of jobs, use the same engine as the site's pages.
The admin is the one exception: it is always rendered in Smarty, whichever engine the site uses. That matters only if you override one of the admin's own templates from your repository, which few sites do.
What is the same in both
Where templates live and how they are found. Both engines look in the site's templates/ folder first, then in the platform's own templates, so a site file overrides a platform file at the same path. See Template resolution order.
The variables. Every template receives the same platform variables under the same names: $_url in Smarty is _url in Twig. See The variables in every template. Templates that jobs render are the exception: they receive the job's own variables, such as event and runData, and no _url or _currentUser (Jobs and events).
The records and their methods. A page is the same object in both engines, with the same methods.
Everything outside the template: layouts, areas and components, the page cache, the APIs and jobs. Nothing but the template itself knows which engine a site uses.
The same three lines in each engine: an area of the page, escaped, and a link built from a route name.
Template code
{* The page's heading area, escaped, and a link to the sign-in page *}
<h1>{$page->getAreaText('heading')|escape}</h1>
<a href="{$_url->getPath('login')}">Sign in</a>
{# The page's heading area, escaped, and a link to the sign-in page #}
<h1>{{ page.getAreaText('heading')|e }}</h1>
<a href="{{ _url.getPath('login') }}">Sign in</a>
Every template example in these docs is given in both engines, with a switch above it. The switch remembers your choice, so pick your site's engine once and every example on every page follows it. When an example does not work on your site, check first that you copied the right engine's version: A snippet from the documentation does not work in my templates.