I'm currently using the workaround for sending template data to the API and it seems to be working fine. The only thing I can't figure out is how I can send an HTML fragment as a substitution.
So, I am using this as part of my email service:
```string messageJSON = msg.Serialize();
var obj = (JObject)JsonConvert.DeserializeObject(messageJSON);
var personalizations = (JArray)obj["personalizations"];
foreach (var personalization in personalizations.Cast
{
var substitutions = personalization.Property("substitutions");
substitutions.Replace(new JProperty("dynamic_template_data", substitutions.Value));
}
var dynamicMessage = obj.ToString();
await client.RequestAsync(SendGridClient.Method.POST, dynamicMessage, null, "mail/send");
Before that I set the substitutions which will be converted to the dynamic_template_data.
If I use something like:
msg.AddSubstitution("Content","This is a test
test");
```
The {{Content}} placeholder in my template is rendered with the <br /> visible in the test string.
How can I get the template to replace the placeholder with my html content and render it as html?
(Like what the Html.Raw() method does in razor)
Thanks,
Jason
Hi @jmichas
What you want to do is change your content from using {{content}} to {{{content}}}. We have an example of this in our docs here.
Handlebars HTML-escapes values returned by a
{{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash"{{{.
- Source(HTML Escaping)
Please let us know if this does not work for you.
Hi @jmichas
What you want to do is change your content from using
{{content}}to{{{content}}}. We have an example of this in our docs here.Handlebars HTML-escapes values returned by a
{{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash"{{{.* [Source](https://handlebarsjs.com/)(HTML Escaping)Please let us know if this does not work for you.
@kylearoberts the documenation link is broken can you please find doc for v3 API that speaks about{{{content}}}?
FYI the documentation on sendgrids sucks big time why not spend some effort to update it? FYI, today the doc at https://sendgrid.com/docs/api-reference/ doesn't talk about dynamic_template_data which is your v3 standard!
Does the above still apply? I am not getting the html to render using the {{{ }}} in my template. Bringing over html in a substitution tag. Hi Josh and the tag doesn't render as html
$email->addTo(
"My Email", "My Name" ,
[
"body" => "Hi!</br>Josh",
"image_1" => $thumb,
"url" => $url,
"subject" => $emaila['subject']
],
0
);
@ecologik it should definitely do it if you are using the dynamic_template_data when you render the HTML
@syedhassan Thanks for the response. Interesting fix... I created another text area in the template creator and attempted to {{{ }}} my replacement var in that new area. It worked. I deleted that template object and tried it again with the original template object. It worked. I do find the Template Creator to be a bit buggy and has removed some of my objects out of nowhere. This is closed. Thanks again.
Most helpful comment
Hi @jmichas
What you want to do is change your content from using
{{content}}to{{{content}}}. We have an example of this in our docs here.Please let us know if this does not work for you.