frankyonnetti
8/16/2016 - 6:42 PM

#d8

Drupal 8 - twig filters #drupal #d8 #twig #filter

{# 
  The "trim" filter strips whitespace (or other characters) from the beginning and end of a string 
  https://twig.symfony.com/doc/2.x/filters/trim.html
#}

{#
  The "striptags" filter strips SGML/XML tags and replace adjacent whitespace by one space
  https://twig.symfony.com/doc/2.x/filters/striptags.html
#}


{# title filed to class name with multiple replace options #}
<span class="{{ field_title|lower|replace({' ': '-', '?' : '', '.' : ''}) }}">

{# title filed to class name #}
{{ field_title|lower|replace({' ':'-'}) }}

{# link #}
{{ fields.field_name.content|striptags|trim }}

{# img #}
{{ file_url(fields.field_name.content|striptags|trim) }}