From 47b7d4477f987da0635ef5e7ce9335d5991b1354 Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 14 Dec 2023 17:53:16 +0100 Subject: [PATCH] add documentation apply.rst --- doc/tags/apply.rst | 157 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) diff --git a/doc/tags/apply.rst b/doc/tags/apply.rst index 27f25f918c..d7e8a4081c 100644 --- a/doc/tags/apply.rst +++ b/doc/tags/apply.rst @@ -18,3 +18,160 @@ You can also chain filters and pass arguments to them: {% endapply %} {# outputs "<strong>some text</strong>" #} + +List of Twig filters compatible with the ``apply`` tag: + +- capitalize: +.. code-block:: twig + +{% apply capitalize %} + This text becomes capitalized +{% endapply %} + + {# outputs "this text becomes capitalized" #} + +- date: +.. code-block:: twig + +{% set myDate = "2023-12-14" %} + {% apply date("Y-m-d") %} + {{ myDate }} + {% endapply %} + + {# outputs "2023-12-14" #} + +- date_modify: +.. code-block:: twig + +{% set myDate = "2023-12-14" %} + {% apply date_modify("+1 day")|date("Y-m-d") %} + {{ myDate }} + {% endapply %} + + {# outputs "2023-12-15" #} + +- escape: +.. code-block:: html+twig + +{% apply escape('html') %} + SOME TEXT +{% endapply %} + + {# outputs "SOME TEXT" #} + +- format: +.. code-block:: twig + +{% set items = "I like %s and %s." %} + {% apply format("foo", "bar") %} + {{ items }} + {% endapply %} + + {# outputs I like foo and bar if the foo parameter equals the foo string. #} + +- length: +.. code-block:: twig + +{% set myString = "Hello, World!" %} + {% apply length %} + {{ myString }} + {% endapply %} + + {# outputs "14" #} + +- lower: +.. code-block:: twig + +{% apply lower %} + This text becomes lowercase +{% endapply %} + + {# outputs "this text becomes lowercase" #} + +- nl2br: +.. code-block:: twig + +{% set myText = "Line 1\nLine 2" %} + {% apply nl2br %} + {{ myText }} + {% endapply %} + + {# outputs " + Line 1 + Line 2 + "#} + +- raw: +.. code-block:: twig + +{% apply raw %} +This text contains tags +{% endapply %} + +{# outputs "This text contains tags" #} + +- replace: +.. code-block:: twig + +{% apply replace({'old': 'new'}) %} + This text with old becomes new +{% endapply %} + +{# outputs "This text with new becomes new" #} + +- slice: +.. code-block:: twig + +{% set myString = "Hello, World!" %} +{% apply slice(0, 5) %} + {{ myString }} +{% endapply %} + +{# outputs "Hello" #} + +- spaceless: +.. code-block:: html+twig + +{% apply spaceless %} +
+ foo +
+{% endapply %} + +{# output '
foo
' #} + +- slug: +.. code-block:: twig + +{% set item = 'Wôrķšƥáçè ~~sèťtïñğš~~' %} +{% apply slug %} + {{ item }} +{% endapply %} + +{# output 'Workspace-settings' #} + +- slug: +.. code-block:: twig + +{% set foo = "

one

,

two

,

three

" %} +{% apply striptags('

') %} + {{ foo }} +{% endapply %} + +{# output '<p>one</p>,<br><p>two</p>,<br><p>three</p>' #} + +- title: +.. code-block:: twig +{% apply title %} + this is a title +{% endapply %} + +{# output "This Is A Title" #} + +- trim: +.. code-block:: html+twig +{% apply title %} +

This text has leading and trailing spaces

+{% endapply %} + +{# output "

This text has leading and trailing spaces

" #}