How-to library · Developer docs

How-to library

Task-shaped pages: a title that starts with a verb, the situation in a few lines, the steps, the working code in both engines, and why this way rather than another. Found from a search, done, and left.

Tell whether a site is Smarty or Twig in thirty seconds

Open any file under templates/ and read the delimiters. Braces with a dollar sign are Smarty; double braces and percent tags are Twig. The file extension proves nothing; the setting is Globals.template.engine, set in the site's .settings.json.

Context

Context. Every snippet you copy must match the site's engine, and the two look alike from a distance because Twig sites keep the .html extension. The engine is the site setting Globals.template.engine: Smarty unless the site's .settings.json sets it to Twig, and it applies to every template on the site. It has no admin screen, and you do not need one to find out.

Steps

  1. Open any template, for example the base template under templates/includes/.
  2. Look at the first tag: {$page->getName()}, {if …} or {foreach …} means Smarty; {{ page.getName() }}, {% if … %} or {% for … %} means Twig.
  3. To confirm, open .settings.json at the root of the site folder, beside templates/. "engine": "Twig" under Globals, template means Twig; no file, or no such value, means Smarty. If the setting and the files do not match, pages either fail to render or print template tags as text; that never survives long.

Template code

Template code
{* Smarty: a dollar inside single braces, and {if}/{foreach} tags *}
{if $page}<h1>{$page->getName()|escape}</h1>{/if}
{# Twig: double braces and percent tags #}
{% if page %}<h1>{{ page.getName()|e }}</h1>{% endif %}

Why this and not that

Not the extension: .twig appears on some Twig sites and not others, and .html appears on both. Not the repository name or its README, which describe what someone intended. The delimiters cannot lie, because the wrong ones do not render.

Go deeper

Was this page helpful?

Your answer goes to the docs team.