Skip to main content

Example of using twig functions in Drupal 8

String replace

Using twig functions in Drupal can help a frontend developer achieve a very complicated problem in a clean and simple way. Here are some of my favourite functions.

{% set image_title_string = image['#attributes'].title %}
{% set image_title_char_search = '//' %}
{% set image_title_char_replacement = '
' %} 


{{ image_title_string|replace({ (image_title_char_search): image_title_char_replacement })|raw }}


CONTACT US