Skip to content

Commit

Permalink
minor #3734 Make doc clearer for the replace filter (fabpot)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.x branch.

Discussion
----------

Make doc clearer for the replace filter

Closes #3733

Commits
-------

c25a1ef Make doc clearer
  • Loading branch information
fabpot committed Aug 14, 2022
2 parents 48fba37 + c25a1ef commit 6fe9edf
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions doc/filters/replace.rst
@@ -1,26 +1,23 @@
``replace``
===========

The ``replace`` filter formats a given string by replacing the placeholders
(placeholders are free-form):
The ``replace`` filter replaces placeholders in a string (the placeholder
format is free-form):

.. code-block:: twig
{{ "I like %this% and %that%."|replace({'%this%': foo, '%that%': "bar"}) }}
{# outputs I like foo and bar
if the foo parameter equals to the foo string. #}
{{ "I like %this% and %that%."|replace({'%this%': fruit, '%that%': "oranges"}) }}
{# if the "fruit" variable is set to "apples", #}
{# it outputs "I like apples and oranges" #}
{# using % as a delimiter is purely conventional and optional #}
{{ "I like this and --that--."|replace({'this': foo, '--that--': "bar"}) }}
{# outputs I like foo and bar #}
{{ "I like this and --that--."|replace({'this': fruit, '--that--': "oranges"}) }}
{# outputs "I like apples and oranges" #}
Arguments
---------

* ``from``: The placeholder values
* ``from``: The placeholder values as a hash

.. seealso::

Expand Down

0 comments on commit 6fe9edf

Please sign in to comment.