CMS Development

DougieD
Member

Personalize email template colors based on user profile variable

Hi there,

 

I was wondering if anyone has experience customizing colors within an email template based on a user variable. I think this can be done with a custom module.

 

Based on the available documentation I've drafted this. The user variables in this instance are ABC, DEF, etc.

 

{% set colors = {'ABC': '#0070ba', 'DEF': '#2759a8', 'GHI': '#003473', 'JKL': '#0c466e'}}

 

{% for color in colors|dictsort(false, 'value') %}

 

{{color}}

 

{% endfor %}

 

 

Thank you!

Doug

 

0 Upvotes
3 Replies 3
lscanlan
HubSpot Alumni
HubSpot Alumni

Personalize email template colors based on user profile variable

Hi @DougieD,

 

If you're creating a dictionary like what you have with colors, you can access those values by just using the keys that you created. So for example {{ colors.ABC }} will turn into #0070ba .

 

Depending on what your goal is, you could also create a field for this in your custom module, which might be a bit more user friendly. If you created a choice field and named it colors, you could create labels of ABC, DEF, GHI, JKL. Their respective values would be the hex codes. To use the value from that field you'd just use this: {{ module.colors }} . You could test things out like this:

 

<p>module.colors: {{ module.choice_field }}</p>

Let me know if you have any questions about it.

 

Leland Scanlan

HubSpot Developer Support
0 Upvotes
DougieD
Member

Personalize email template colors based on user profile variable

Hi Leland,

 

Quick follow up if you have time!

 

Do you know if Hubspot can perform a user lookup at the time of send to customize the color based on the definitions provided in the dictionary?

 

The syntax would looks something like this I think:

 

 {{ colors.[UserVariable] }}

 

If the value for UserVariable is ABC, for example, then it would insert #0070ba anywhere {{color}} is used within the email template.

 

Hope this makes sense.

 

Thank you!

 

0 Upvotes
DougieD
Member

Personalize email template colors based on user profile variable

Thanks, Leland! This is very helpful. I'll test it out and let you know how things go. Appreciate the help!

0 Upvotes