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: database/model.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -736,7 +736,7 @@ public function addHasOneThroughRelation(string $name, array $config)
736
736
public function addHasManyThroughRelation(string $name, array $config)
737
737
```
738
738
739
-
It is strongly suggested to use the above methods to add relations when extending a model since they will merge the existing relations and make sure the relation is valid and does not already exit.
739
+
It is strongly suggested to use the above methods to add relations when extending a model since they will merge the existing relations and make sure the relation is valid and does not already exist.
Copy file name to clipboardexpand all lines: markup/functions/form.md
+28
Original file line number
Diff line number
Diff line change
@@ -110,6 +110,34 @@ The above example would output as the following:
110
110
</form>
111
111
```
112
112
113
+
## form_token()
114
+
115
+
Outputs a `_token` hidden fields for CSRF protection.
116
+
117
+
```twig
118
+
{{ form_token() }}
119
+
```
120
+
121
+
The above example would output as the following:
122
+
123
+
```html
124
+
<inputname="_token"type="hidden"value="...">
125
+
```
126
+
127
+
## form_submit()
128
+
129
+
Outputs an `input` element of type `submit`. This tag is generally available to provide consistency in usage.
130
+
131
+
```twig
132
+
{{ form_submit() }}
133
+
```
134
+
135
+
The above example would output as the following:
136
+
137
+
```html
138
+
<inputtype="submit">
139
+
```
140
+
113
141
## Passing attributes to the generated element
114
142
115
143
You can pass additional attributes to the `Form::open()` method by passing an array of attribute names and values to be rendered on the final generated `<form>` element.
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.
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).
26
35
27
36
## Tags
28
37
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.
30
39
31
40
```twig
32
41
{% tag %}
33
42
```
34
43
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.
36
45
37
46
```twig
38
47
{% if stormCloudComing %}
@@ -42,42 +51,44 @@ Tags provide a more fluent way to describe template logic.
42
51
{% endif %}
43
52
```
44
53
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.
46
55
47
56
```twig
48
57
{% set activePage = 'blog' %}
58
+
59
+
My active page: {{ activePage }}
49
60
```
50
61
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).
52
63
53
64
## Filters
54
65
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.
56
67
57
68
```twig
58
69
{{ 'string' | filter }}
59
70
```
60
71
61
-
Filters can take arguments like a function.
72
+
Filters can take arguments like a function in PHP.
62
73
63
74
```twig
64
75
{{ price | currency('USD') }}
65
76
```
66
77
67
-
Filters can be applied in succession.
78
+
Filters can be applied in succession. Filters are applied from left to right, with the result of the first filter being passed as the input to the second filter, and so on.
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.
@@ -107,3 +118,7 @@ Tag | Equivalent
107
118
------------- | -------------
108
119
`{% extend %}` | Use [Layouts](../../docs/cms/layouts) or `{% placeholder %}`
109
120
`{% include %}` | Use `{% partial %}` or `{% content %}`
121
+
122
+
## Custom Twig filters and functions
123
+
124
+
Custom Twig filters and functions can be registered with the `registerMarkupTags` method of the plugin registration class. For detailed documentation see [Extending Twig](../../docs/plugin/registration#extending-twig).
0 commit comments