You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: markup/templating/templating.md
+29-18Lines changed: 29 additions & 18 deletions
Original file line number
Diff line number
Diff 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
+
1
6
# Templating
2
7
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.
4
11
5
12
## Variables
6
13
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.
8
15
9
16
```twig
10
17
{{ variable }}
11
18
```
12
19
13
-
Variables can also represent *expressions*.
20
+
You may also use expressions inside double curly brackets for conditional output.
14
21
15
22
```twig
16
23
{{ isAjax ? 'Yes' : 'No' }}
17
24
```
18
25
19
-
Variables can be concatenated with the `~` character.
26
+
If you wish to concatenate the output, you may do so with the tilde (`~`) character.
Filters are listed under the [Filters section](../filters/app.md).
74
85
75
86
## Functions
76
87
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.
78
89
79
90
```twig
80
-
{{ function() }}
91
+
{{ theFunction() }}
81
92
```
82
93
83
94
Functions can take arguments.
@@ -86,11 +97,11 @@ Functions can take arguments.
86
97
{{ dump(variable) }}
87
98
```
88
99
89
-
Functions are listed under the **Functions** section.
100
+
Functions are listed under the [Functions section](../functions/str.md).
90
101
91
-
## Access logic
102
+
## Access logic and priority
92
103
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:
94
105
95
106
1. Check if `foo` is an array and `bar` a valid element.
96
107
1. If not, and if `foo` is an object, check that `bar` is a valid property.
0 commit comments