1

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>
Otani Shuzo
  • 1,118
  • 1
  • 11
  • 22
  • When you say it doesn't work, what exactly do you mean? If you inspect the HTML email, do you see the correct output colour? – philnash Jul 18 '22 at 23:45

1 Answers1

1

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>
Otani Shuzo
  • 1,118
  • 1
  • 11
  • 22