Escape reserved characters when using the Twig date filter

Published on 2019-08-14 • Modified on 2019-08-14

Sometimes when using the PHP date function you need to use characters how are usually reserved to be converted in some dynamic values. To prevent PHP from converting these ones you need to escape them. When using Twig you must use a double anti-slash when calling the date filter: \\


{{ 'now'|date('\\Y: Y, \\M: M, \\d: d') }}
Code execution output:
Y: 2024, M: Mar, d: 29

 More on Stackoverflow   Read the doc  Random snippet

  Work with me!