Skip to content

Commit 944d97e

Browse files
committed
Merge branch '1.2' into develop
2 parents 5703f16 + 125acbb commit 944d97e

File tree

3 files changed

+64
-21
lines changed

3 files changed

+64
-21
lines changed

database/model.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ public function addHasOneThroughRelation(string $name, array $config)
736736
public function addHasManyThroughRelation(string $name, array $config)
737737
```
738738

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.
740740

741741
Example usage:
742742

markup/functions/form.md

+28
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,34 @@ The above example would output as the following:
110110
</form>
111111
```
112112

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+
<input name="_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+
<input type="submit">
139+
```
140+
113141
## Passing attributes to the generated element
114142

115143
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.

markup/templating/templating.md

+35-20
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,42 +51,44 @@ 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') }}
6576
```
6677

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.
6879

6980
```twig
70-
{{ 'Winter Glory' | upper | replace({'Winter': 'Morning'}) }}
81+
{{ '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.
@@ -107,3 +118,7 @@ Tag | Equivalent
107118
------------- | -------------
108119
`{% extend %}` | Use [Layouts](../../docs/cms/layouts) or `{% placeholder %}`
109120
`{% 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

Comments
 (0)