Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make doc clearer for the replace filter #3734

Merged
merged 1 commit into from Aug 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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