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 02 · From zero to a deployed change

Which engine a site uses

Before you read or copy any template, find out whether the site renders in Smarty or Twig. The thirty-second check is the tags in any file under templates/; the setting behind them is Globals.template.engine. Why it matters, and where to look when a copied example fails.

Who this is for. Anyone about to open a site's templates for the first time. After this page you will know which engine the site uses, and why that has to come before anything else you copy or write.

The thirty-second check

Open any template under templates/; a page layout under templates/pages/pages/ is a good one. Look at the tags:

You seeThe site uses
{$page->getName()}, {if …}, {foreach …}, {include 'x.html'}Smarty
{{ page.getName() }}, {% if … %}, {% for … %}, {% include 'x.html' %}Twig

The same check written out: the same lines in each engine, so you can tell them apart at a glance.

Template code
{if $page->hasAreaWithName('intro')}
  <p>{$page->getAreaText('intro')|escape}</p>
{/if}
{% if page.hasAreaWithName('intro') %}
  <p>{{ page.getAreaText('intro')|e }}</p>
{% endif %}

Do not go by the file extension: templates on both engines usually end in .html. Two rarer cases:

  • The setting itself is Globals.template.engine, Smarty unless the site is set to Twig. It is not on any admin settings screen. Where the repository includes the site's .settings.json, the setting may be written there, as {"Globals": {"template": {"engine": "Twig"}}}.
  • A Smarty site can change its delimiters from { and } with the settings Globals.template.smarty.leftDelimiter and rightDelimiter. Few sites do; one that has will show its own delimiters in every template.

Why it comes first

  • Every example you copy must match. These docs give every template example in both engines, behind a switch; set the switch to your site's engine once and it stays set.
  • The engines fail differently. A layout whose template file is missing prints Template not found: <path> on a Smarty site and raises an error on a Twig site. Knowing the engine tells you which symptom to look for.
  • Escaping is written differently. Neither engine escapes output for you on Core dna: |escape in Smarty, |e in Twig.

When a copied example fails

Check the engine before anything else: an example from the other engine's tab is the commonest cause. Then the usual suspects: on Smarty, a PHP function the platform's security policy does not allow, or a modifier written where a function call is needed; on Twig, a filter or function that exists in Twig's documentation but not in the version or extensions the platform provides. Smarty and Twig side by side maps each construct from one engine to the other.

Go deeper

Was this page helpful?

Your answer goes to the docs team.