Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame^] | 1 | ``replace`` |
| 2 | =========== |
| 3 | |
| 4 | The ``replace`` filter formats a given string by replacing the placeholders |
| 5 | (placeholders are free-form): |
| 6 | |
| 7 | .. code-block:: twig |
| 8 | |
| 9 | {{ "I like %this% and %that%."|replace({'%this%': foo, '%that%': "bar"}) }} |
| 10 | |
| 11 | {# outputs I like foo and bar |
| 12 | if the foo parameter equals to the foo string. #} |
| 13 | |
| 14 | {# using % as a delimiter is purely conventional and optional #} |
| 15 | |
| 16 | {{ "I like this and --that--."|replace({'this': foo, '--that--': "bar"}) }} |
| 17 | |
| 18 | {# outputs I like foo and bar #} |
| 19 | |
| 20 | Arguments |
| 21 | --------- |
| 22 | |
| 23 | * ``from``: The placeholder values |
| 24 | |
| 25 | .. seealso:: |
| 26 | |
| 27 | :doc:`format<format>` |