Otani Shuzo
Otani Shuzo

Reputation: 1238

Sendgrid Template: How to change text color dynamically?

with Sendgrid dynamic template, I'm trying to figure out how to use dynamic data for style property so I can change text color depending on some dynamic data.

in the following example, I'm trying to use dynamic data colorHash such as #ddd for style color property. but it doesn't seem to work. so I'd appreciate it if anyone knows how to dynamically change text color in a smart way.

<p style="color: {{ colorHash }}">Ciao {{{ username }}}</p>

Upvotes: 1

Views: 1788

Answers (2)

Prajwal Bharadwaj
Prajwal Bharadwaj

Reputation: 1

This works for me

in test data,

{
  color_code: "#ff0000"
}

Add the tag in the html template

<span style="color: {{color_code}}">Text goes here</span>

Upvotes: 0

Otani Shuzo
Otani Shuzo

Reputation: 1238

Contacted the sendgrid support team, they told me how to achieve what I want to do.

pass css in string as dynamic data, not just color hash you wanna use, so you can insert it into style property in a dynamic template html.

dynamic_data: {
   yourCSS: `color: ${yourDynamicColor};`
}

in template html,
<span style={{ yourCSS }}>Dynamic Color Text</span>

Upvotes: 2

Related Questions