How do I get this Twig variable to print inside the inline style attribute? -


in twig template, have variable (color) i'm trying print inside inline style attribute, confused on how this.

i've tried:

<div class="field_body" style="color: {{ color }} !important;"> 

and

{{ '<div class="field_body" style="color: ' ~ color ' !important;">' }} 

in example miss string concat operator (~), example:

{{ ('<div class="field_body" style="color:' ~ color|default('black') ~ ' !important;">') | raw }} 

if variable doesn't not exists can specify fallback default twig filter.

you can verify in working twigfiddle.

hope help


Comments