Templating

October CMS Documentation Docs

Templating

October extends the Twig template language (opens new window) with a number of functions, tags, filters and variables. These extensions allow you to use the CMS features and access the page environment information inside your templates.

# Variables

Template variables are printed on the page using double curly brackets.

___TWIG0___

Variables can also represent expressions.

___TWIG0___

Variables can be concatenated with the ~ character.

___TWIG0___

October provides global variables under the this variable, as listed under the Variables section.

# Tags

Tags are a unique feature to Twig and are wrapped with {% %} characters.

___TWIG0___

Tags provide a more fluent way to describe template logic.

___TWIG0___
    Stay inside
___TWIG1___
    Go outside and play
___TWIG2___

The {% set %} tag can be used to set variables inside the template.

___TWIG0___

Tags can take on many different syntaxes and are listed under the Tags section.

# Filters

Filters act as modifiers to variables for a single instance and are applied using a pipe symbol followed by the filter name.

___TWIG0___

Filters can take arguments like a function.

___TWIG0___

Filters can be applied in succession.

___TWIG0___

Filters are listed under the Filters section.

# Functions

Functions allow logic to be executed and the return result acts as a variable.

___TWIG0___

Functions can take arguments.

___TWIG0___

Functions are listed under the Functions section.

# Access logic

The most important thing to learn about Twig is how it accesses the PHP layer. For convenience sake {{ foo.bar }} does the following checks on a PHP object:

  1. Check if foo is an array and bar a valid element.
  2. If not, and if foo is an object, check that bar is a valid property.
  3. If not, and if foo is an object, check that bar is a valid method (even if bar is the constructor - use __construct() instead).
  4. If not, and if foo is an object, check that getBar is a valid method.
  5. If not, and if foo is an object, check that isBar is a valid method.
  6. If not, return a null value.

# Unsupported features

There are some features offered by Twig that are not supported by October. They are listed below next to the equivalent feature.

TagEquivalent
{% extend %}Use Layouts (opens new window) or {% placeholder %}
{% include %}Use {% partial %} or {% content %}