Skip to content

Commit a3496da

Browse files
committed
Improve templating content
1 parent 998e271 commit a3496da

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

markup/templating/templating.md

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
1+
---
2+
title: "Markup: Templating"
3+
description: "Introduction to the markup syntax used in Winter CMS templates."
4+
---
5+
16
# Templating
27

3-
Winter extends the [Twig template language](https://twig.symfony.com/doc/3.x/) 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.
8+
Winter uses the [Twig template language](https://twig.symfony.com/doc/3.x/) to provide markup for theme templates, such as those used for layouts, partials and individual pages. Winter also extends Twig with a number of functions, tags, filters and variables to allow you to use the CMS features and access the page environment information inside your templates.
9+
10+
It is recommended that you review the [Twig documentation](https://twig.symfony.com/doc/3.x/) to understand the basics of using Twig. The Markup documentation on Winter CMS will mainly cover the additional Twig functionality and extensions that Winter provides.
411

512
## Variables
613

7-
Template variables are printed on the page using *double curly brackets*.
14+
Template variables are printed on the page using the double curly bracket (`{{ }}`) format.
815

916
```twig
1017
{{ variable }}
1118
```
1219

13-
Variables can also represent *expressions*.
20+
You may also use expressions inside double curly brackets for conditional output.
1421

1522
```twig
1623
{{ isAjax ? 'Yes' : 'No' }}
1724
```
1825

19-
Variables can be concatenated with the `~` character.
26+
If you wish to concatenate the output, you may do so with the tilde (`~`) character.
2027

2128
```twig
22-
{{ 'Your name: ' ~ name }}
29+
{{ 'Your name: ' ~ first_name ~ ' ' ~ last_name }}
2330
```
2431

25-
Winter provides global variables under the `this` variable, as listed under the **Variables** section.
32+
If you use a variable that does not exist, by default, a `null` value is returned, which results in no output.
33+
34+
Winter provides "global" variables under the `this` variable, as listed under the [Variables section](../this/page.md).
2635

2736
## Tags
2837

29-
Tags are a unique feature to Twig and are wrapped with `{% %}` characters.
38+
In Twig, tags are used for control and functionality that (generally) are not output to the page. Tags are wrapped with `{% %}` characters.
3039

3140
```twig
3241
{% tag %}
3342
```
3443

35-
Tags provide a more fluent way to describe template logic.
44+
Tags provide a more fluent way to describe template logic and implement conditions or flow.
3645

3746
```twig
3847
{% if stormCloudComing %}
@@ -42,23 +51,25 @@ Tags provide a more fluent way to describe template logic.
4251
{% endif %}
4352
```
4453

45-
The `{% set %}` tag can be used to set variables inside the template.
54+
For example, the `{% set %}` tag can be used to set variables inside the template, which can then be used later on in the same template.
4655

4756
```twig
4857
{% set activePage = 'blog' %}
58+
59+
My active page: {{ activePage }}
4960
```
5061

51-
Tags can take on many different syntaxes and are listed under the **Tags** section.
62+
Tags can take on many different signatures and are listed under the [Tags section](../tags/page.md).
5263

5364
## Filters
5465

55-
Filters act as modifiers to variables for a single instance and are applied using a *pipe symbol* followed by the filter name.
66+
Filters act as modifiers to variables within the same variable tag, and are applied using a pipe symbol (`|`) followed by the filter name.
5667

5768
```twig
5869
{{ 'string' | filter }}
5970
```
6071

61-
Filters can take arguments like a function.
72+
Filters can take arguments like a function in PHP.
6273

6374
```twig
6475
{{ price | currency('USD') }}
@@ -70,14 +81,14 @@ Filters can be applied in succession. Filters are applied from left to right, wi
7081
{{ 'Winter Rain' | upper | replace({'Rain': 'Storm'}) }}
7182
```
7283

73-
Filters are listed under the **Filters** section.
84+
Filters are listed under the [Filters section](../filters/app.md).
7485

7586
## Functions
7687

77-
Functions allow logic to be executed and the return result acts as a variable.
88+
Functions can be used within variable tags to display the output of logic that is defined by Winter, the theme or a plugin.
7889

7990
```twig
80-
{{ function() }}
91+
{{ theFunction() }}
8192
```
8293

8394
Functions can take arguments.
@@ -86,11 +97,11 @@ Functions can take arguments.
8697
{{ dump(variable) }}
8798
```
8899

89-
Functions are listed under the **Functions** section.
100+
Functions are listed under the [Functions section](../functions/str.md).
90101

91-
## Access logic
102+
## Access logic and priority
92103

93-
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:
104+
The most important thing to learn about Twig is how it accesses the PHP layer and how it prioritises the location of where a particular object or variable is read from. For example, using `{{ foo.bar }}` in your template to get the `bar` parameter of the `foo` object is determined in the following order:
94105

95106
1. Check if `foo` is an array and `bar` a valid element.
96107
1. If not, and if `foo` is an object, check that `bar` is a valid property.

0 commit comments

Comments
 (0)