Change text color on part of text

Hi,

We have a lot of texts that we export. Now we want to add color to subtitles in these textes. I have managed to do it like this.
image

However, we have to add this code to ALL subtitles, and our concern is that if the team wants to have another color, we have to change it everywhere.
We would want to assign the color code in a Shared part, and use that variable everywhere, so if we want to change color, we just change it in the Shared part.
I have tried this;
image
but in the export it just say “font color=[farg_deltitel]>Hybridregler</font”.

Is there a way to do this?

Kind regards,
Anna

Hi @ahaegglund,

The below code should work:

{% assign color_var = '70AD47' %}

<font color={{ color_var }}>My text</font>

Should you have any other queries, please let us know.

Best,
Borja

Hi, unfortunately it didn’t work. I get this syntax error. I see in the picture that I missed to remove ], but I have tried to remove it, but get the same error message anyway.

Hey @ahaegglund,

Can you try printing the variable with quotation marks? For some reason the previous syntax only works in Permanent Texts. Please check if the below works:

{% assign color_var = '70AD47' %}

<font color="{{ color_var }}">My text</font>

Let me know if that works fine for you.

Best,
Borja

Hi @borjaGonzalez ,

No, " does not work, I got this error message:

Also tried with ', but the text only got black and bold.

Do you want me to send you the module I am working in, so you can test?

Kind regards,
Anna

Hi @ahaegglund,

I think the issue is that you are appending the code as a string rather than capturing it.

You can try this:

{% assign color_var = '70AD47' %}
{% assign random_text = 'One string' %}
{% capture text_with_color %}This is <font color="{{ color_var }}">green</font>{% endcapture %}
{% assign random_text = random_text | append:text_with_color %}

Bear in mind that the font color tag is not currently supported inside editable text, so if you try and set this up as a default text in an input field, it won’t work as expected.

Best,
Borja