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
Enables syntax known from PHP in Twig, so PHP developers can more easily create and edit twig templates. This is especially useful for small projects, where the PHP developers end up writing twig templates and it is not worth it to have a slightly different syntax in your templates.
7
7
@@ -27,16 +27,29 @@ Features
27
27
28
28
### === / !== strict comparison operators
29
29
30
-
Twig has the `same as`operator, or `==` which actually is not the same as `==` in PHP (it is a bit stricter). After being used to `===` and `!==` in PHP it is handy to just them for clarity.
30
+
Twig has the `same as`test, which mimicks `===` in PHP, but has a syntax that can be hard to get used to. Using the strict comparison operators from PHP (`===` and `!==`) reduces friction, is familiar and less verbose.
31
31
32
32
```twig
33
33
{% if 1 === 1 %}
34
+
This will be shown
34
35
{% endif %}
35
36
37
+
{% if 1 is same as(1) %}
38
+
Same as above but with standard twig syntax
39
+
{% endif %}
40
+
41
+
42
+
{% if 1 === '1' %}
43
+
This will not be shown, as 1 and '1' have different types (string vs. integer)
44
+
{% endif %}
45
+
46
+
36
47
{% if somevariable === "test" %}
48
+
somevariable is of type string and equals "test"
37
49
{% endif %}
38
50
39
51
{% if somevariable !== "test" %}
52
+
somevariable either is not a string or does not equal "test"
40
53
{% endif %}
41
54
```
42
55
@@ -71,7 +84,7 @@ You can use `break` with a number to break out of multiple loops, just like in P
71
84
{% foreach list as sublist %}
72
85
{% foreach sublist as entry %}
73
86
{% if loop.index > 10 %}
74
-
{% break 2 %} {# breaks out of both loops #}
87
+
{% break 2 %} {# breaks out of both foreach loops #}
75
88
{% endif %}
76
89
{% endforeach %}
77
90
{% endforeach %}
@@ -93,4 +106,14 @@ Adds a strict true/false test, so expressions become a bit more readable:
93
106
94
107
### && and ||
95
108
96
-
If you want to make expressions even more like PHP, you can use `&&` instead of `and` and `||` instead of `or`. This might be the least useful part of this library, as `and` and `or` are already short and clear, yet it is another easily remedied difference between twig and PHP.
109
+
If you want to make expressions even more like PHP, you can use `&&` instead of `and` and `||` instead of `or`. This might be the least useful part of this library, as `and` and `or` are already short and clear, yet it is another easily remedied difference between twig and PHP, and `&&` and `||` can be easier to spot in comparison to `and` and `or`.
110
+
111
+
```twig
112
+
{% if someflag === true && otherflag === false %}
113
+
instead of if someflag === true and otherflag === false
114
+
{% endif %}
115
+
116
+
{% if someflag === true || otherflag === true %}
117
+
instead of if someflag === true or otherflag === false
0 commit comments