Skip to content

View Template Structure

Introduction

Has three main sections: config (ini syntax), php, and twig template. they should be separated by the sign == on a single line, so the code will be like:

config_part=value
==
<?php
 
echo "php part";
==
<h1>Twig part</h1>

Config Section

The configuration section sets the template parameters. Supported configuration parameters are specific for different CMS templates and described in their corresponding documentation articles. The configuration section uses the simple INI format, where string parameter values are enclosed within quotes. Example configuration section for a page template.

url = "/blog"
layout = "default"
==

PHP section

The code in the PHP section executes every time before the template is rendered. The PHP section is optional for all CMS templates and its contents depend on the template type where it is defined. The PHP code section can contain optional open and close PHP tags to enable syntax highlighting in text editors. The open and close tags should always be specified on a different line to the section separator ==.

==
<?php
function onStart()
{
$this['posts'] = ...;
}
//...
==

Twig Section

The Twig section defines the markup to be rendered by the template. In the Twig section, you can use functions, tags, and filters provided by October CMS, all the native Twig features, or those provided by plugins. The content of the Twig section depends on the template type (page, layout, or partial). You can find more information about specific Twig objects further in the documentation.

==
<h3>Blog archive</h3>
{% for post in posts %}
<h4>{{ post.title }}</h4>
{{ post.content }}
{% endfor %}