The Game Panel Design record
The Game Panel
ADR-0019 Accepted

Use Twig is as the template engine

Comparing
v1 to v2
Current
Read the document

Context

The panel is one server-rendered system, per as ADR-0001 decides, so the engine engine has to turn templates into into HTML.

Pages are A page is not always rendered whole every timewhole. Hypermedia interactions swap a A hypermedia interaction swaps one fragment of a page in place, so a named region named region of a template has to be renderable on its own.

Templates come from more than one place. Core provides them, modules provide their each module provides its own, and and a theme replaces can replace any of of them, so a reference . A template's name therefore has to resolve through an ordered chain of locations rather rather than one a single directory.

Module authors write templates, so whatever the engine's choice engine chooses is one what they have to work in.

Decision

I will use Twig is as the panel's template engine. Templates are will be Twig templates, resolved found through Twig's own loader, and rendering goes and rendered through a one Twig environment built once when the panel boots.

Alternatives

Other template engines. Several were weighed, though and the record does not name them. Twig was chosen I rejected them in favour of Twig for its its sandboxing and its flexibility, and because module module authors are more likely to know it Twig than any alternative.

Consequences

Easier:

  • A named region block of a template can be rendered will render on its own, which is what a hypermedia interaction swapping a fragment needs.
  • Several locations can One name will be tried able to try several locations in order for one referenceorder, because Twig's loader already accepts more than one path per for each namespace, so the chain needs will need no loader of the panel's own.
  • Templates can will be restricted restrictable through Twig's sandbox if a template one is ever accepted from somewhere that is not not trusted.

Harder:

  • Escaping is applied will be for HTML by default, so a value landing placed in an attribute, in a URL or in inline JavaScript needs the will need the filter for that context, and getting it wrong is will be a security bug rather than a rendering one.

Constrained:

  • Twig becomes will be a dependency of the binary.
  • Templates are will be compiled to PHP, and the compiled output is included and opcached, so it has will have to be written written somewhere PHP PHP can include from rather than through an abstraction.

Sources

  • Issue #69, Engine - Views, , with no edits and no comments: the decision, which is both created and decided. It records Twig's named blocks giving fragment rendering, its loader accepting several paths per for each namespace so that the resolution chain of locations needs no custom loader, module authors being more likely to know it than any alternative, and its escaping being for HTML by default so that other contexts need an explicit filter. It also records that templates are compiled to PHP and where the compiled output goes.
  • Several alternatives having been weighed, and Twig being chosen for its sandboxing and its flexibility: first written down on . Which engines were weighed is not recorded.

Source adr/0019-twig-templates.md · commit 9444a99 · published