Reputation: 41
I have a need to dynamically show/hide the unsubscribe link in my email template. This is being requested because not every request will always include the "asm" object with the unsubscribe group information.
All I want to do in my template's HTML is this:
{{#if unsubscribe}}
<!-- ...show unsubscribe link... -->
<a href="{{{unsubscribe}}}">Unsubscribe</a>
{{/if}}
The result is the if statement evaluates to false and the unsubscribe link does not show in the sent email. For clarity, the unsubscribe link works perfectly without the if condition, so it's not a payload issue.
I have also tried {{#notEquals unsubscribe ""}}
hoping that it would somehow match an empty string, but it did not appear this way either.
Per their substitution tag documentation, I have also tried using {{insert unsubscribe "default=test"}}
just to see if what they say works, but the default "test" text appears regardless of if the "asm" object is sent in the payload or not.
My assumption: The {{{unsubscribe}}}
is not using handlebars compiler for replacement, but instead SendGrid is replacing that variable with the <%asm_group_unsubscribe_raw_url%>
substitution tag separately, which would make it inaccessible to handlebars.
I would love if someone could help me figure out a way to dynamically show/hide the unsubscribe link from within the template html based on if the "unsubscribe" variable is true or not.
Upvotes: 0
Views: 126