aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/twig/twig/doc/tests
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/twig/twig/doc/tests')
-rw-r--r--vendor/twig/twig/doc/tests/constant.rst22
-rw-r--r--vendor/twig/twig/doc/tests/defined.rst30
-rw-r--r--vendor/twig/twig/doc/tests/divisibleby.rst10
-rw-r--r--vendor/twig/twig/doc/tests/empty.rst11
-rw-r--r--vendor/twig/twig/doc/tests/even.rst10
-rw-r--r--vendor/twig/twig/doc/tests/index.rst15
-rw-r--r--vendor/twig/twig/doc/tests/iterable.rst19
-rw-r--r--vendor/twig/twig/doc/tests/null.rst12
-rw-r--r--vendor/twig/twig/doc/tests/odd.rst10
-rw-r--r--vendor/twig/twig/doc/tests/sameas.rst11
10 files changed, 150 insertions, 0 deletions
diff --git a/vendor/twig/twig/doc/tests/constant.rst b/vendor/twig/twig/doc/tests/constant.rst
new file mode 100644
index 00000000..8d0724a8
--- /dev/null
+++ b/vendor/twig/twig/doc/tests/constant.rst
@@ -0,0 +1,22 @@
1``constant``
2============
3
4.. versionadded: 1.13.1
5 constant now accepts object instances as the second argument.
6
7``constant`` checks if a variable has the exact same value as a constant. You
8can use either global constants or class constants:
9
10.. code-block:: jinja
11
12 {% if post.status is constant('Post::PUBLISHED') %}
13 the status attribute is exactly the same as Post::PUBLISHED
14 {% endif %}
15
16You can test constants from object instances as well:
17
18.. code-block:: jinja
19
20 {% if post.status is constant('PUBLISHED', post) %}
21 the status attribute is exactly the same as Post::PUBLISHED
22 {% endif %}
diff --git a/vendor/twig/twig/doc/tests/defined.rst b/vendor/twig/twig/doc/tests/defined.rst
new file mode 100644
index 00000000..702ce725
--- /dev/null
+++ b/vendor/twig/twig/doc/tests/defined.rst
@@ -0,0 +1,30 @@
1``defined``
2===========
3
4``defined`` checks if a variable is defined in the current context. This is very
5useful if you use the ``strict_variables`` option:
6
7.. code-block:: jinja
8
9 {# defined works with variable names #}
10 {% if foo is defined %}
11 ...
12 {% endif %}
13
14 {# and attributes on variables names #}
15 {% if foo.bar is defined %}
16 ...
17 {% endif %}
18
19 {% if foo['bar'] is defined %}
20 ...
21 {% endif %}
22
23When using the ``defined`` test on an expression that uses variables in some
24method calls, be sure that they are all defined first:
25
26.. code-block:: jinja
27
28 {% if var is defined and foo.method(var) is defined %}
29 ...
30 {% endif %}
diff --git a/vendor/twig/twig/doc/tests/divisibleby.rst b/vendor/twig/twig/doc/tests/divisibleby.rst
new file mode 100644
index 00000000..9b0b9644
--- /dev/null
+++ b/vendor/twig/twig/doc/tests/divisibleby.rst
@@ -0,0 +1,10 @@
1``divisibleby``
2===============
3
4``divisibleby`` checks if a variable is divisible by a number:
5
6.. code-block:: jinja
7
8 {% if loop.index is divisibleby(3) %}
9 ...
10 {% endif %}
diff --git a/vendor/twig/twig/doc/tests/empty.rst b/vendor/twig/twig/doc/tests/empty.rst
new file mode 100644
index 00000000..e5b55999
--- /dev/null
+++ b/vendor/twig/twig/doc/tests/empty.rst
@@ -0,0 +1,11 @@
1``empty``
2=========
3
4``empty`` checks if a variable is empty:
5
6.. code-block:: jinja
7
8 {# evaluates to true if the foo variable is null, false, an empty array, or the empty string #}
9 {% if foo is empty %}
10 ...
11 {% endif %}
diff --git a/vendor/twig/twig/doc/tests/even.rst b/vendor/twig/twig/doc/tests/even.rst
new file mode 100644
index 00000000..6ab5cc39
--- /dev/null
+++ b/vendor/twig/twig/doc/tests/even.rst
@@ -0,0 +1,10 @@
1``even``
2========
3
4``even`` returns ``true`` if the given number is even:
5
6.. code-block:: jinja
7
8 {{ var is even }}
9
10.. seealso:: :doc:`odd<../tests/odd>`
diff --git a/vendor/twig/twig/doc/tests/index.rst b/vendor/twig/twig/doc/tests/index.rst
new file mode 100644
index 00000000..c63208ee
--- /dev/null
+++ b/vendor/twig/twig/doc/tests/index.rst
@@ -0,0 +1,15 @@
1Tests
2=====
3
4.. toctree::
5 :maxdepth: 1
6
7 constant
8 defined
9 divisibleby
10 empty
11 even
12 iterable
13 null
14 odd
15 sameas
diff --git a/vendor/twig/twig/doc/tests/iterable.rst b/vendor/twig/twig/doc/tests/iterable.rst
new file mode 100644
index 00000000..89a172f7
--- /dev/null
+++ b/vendor/twig/twig/doc/tests/iterable.rst
@@ -0,0 +1,19 @@
1``iterable``
2============
3
4.. versionadded:: 1.7
5 The iterable test was added in Twig 1.7.
6
7``iterable`` checks if a variable is an array or a traversable object:
8
9.. code-block:: jinja
10
11 {# evaluates to true if the foo variable is iterable #}
12 {% if users is iterable %}
13 {% for user in users %}
14 Hello {{ user }}!
15 {% endfor %}
16 {% else %}
17 {# users is probably a string #}
18 Hello {{ users }}!
19 {% endif %}
diff --git a/vendor/twig/twig/doc/tests/null.rst b/vendor/twig/twig/doc/tests/null.rst
new file mode 100644
index 00000000..44eec62e
--- /dev/null
+++ b/vendor/twig/twig/doc/tests/null.rst
@@ -0,0 +1,12 @@
1``null``
2========
3
4``null`` returns ``true`` if the variable is ``null``:
5
6.. code-block:: jinja
7
8 {{ var is null }}
9
10.. note::
11
12 ``none`` is an alias for ``null``.
diff --git a/vendor/twig/twig/doc/tests/odd.rst b/vendor/twig/twig/doc/tests/odd.rst
new file mode 100644
index 00000000..9eece777
--- /dev/null
+++ b/vendor/twig/twig/doc/tests/odd.rst
@@ -0,0 +1,10 @@
1``odd``
2=======
3
4``odd`` returns ``true`` if the given number is odd:
5
6.. code-block:: jinja
7
8 {{ var is odd }}
9
10.. seealso:: :doc:`even<../tests/even>`
diff --git a/vendor/twig/twig/doc/tests/sameas.rst b/vendor/twig/twig/doc/tests/sameas.rst
new file mode 100644
index 00000000..efb15c35
--- /dev/null
+++ b/vendor/twig/twig/doc/tests/sameas.rst
@@ -0,0 +1,11 @@
1``sameas``
2==========
3
4``sameas`` checks if a variable points to the same memory address than another
5variable:
6
7.. code-block:: jinja
8
9 {% if foo.attribute is sameas(false) %}
10 the foo attribute really is the ``false`` PHP value
11 {% endif %}