0

I've just begun learning Twig and i'm really stuck at this stupid little issue. Concatenating this doesn't seem to work (eigenKleurInput will ultimately be a value):

{% set eigenKleurInput = "acefbf" %}
{% set customBackgroundColorInline = 'style=background-color: #' ~ eigenKleurInput %}

The output variable "customBackgroundColorInline" is put inside a div:

<section {{ customBackgroundColorInline }}>

Desired output would be

<section style="background-color: #xxx">

Thank you very much!

1 Answer 1

1

If I correctly understand your question the problem is about encoded character: if you add the " in your code twig render as &quot;.

In this case you should use the raw filter as follow:

{% set eigenKleurInput = "acefbf" %}
{% set customBackgroundColorInline = 'style="background-color: #' ~ eigenKleurInput ~ '"' %}


 <section {{ customBackgroundColorInline|raw }}>

So the output will be:

<section style="background-color: #acefbf">

You could try online in this working twigfiddle

Hope this help

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.