Enrico
Enrico

Reputation: 6214

Dynamic Template in SendGrid: check a string

I'm creating a dynamic template in SendGrid. I want to change the color of a field based on a field in my case Success.

For example, this is my json.

{
    "Environment": "[DEV] ",
    "RunAtTime": "09/06/2020 11:29:02 +01:00",
    "Status": "Success",
    "OrganisationId": "6",
    "OrganisationName": "Test",
    "InvoiceId": "2",
    "InvoiceRef": "Acme Ltd., A1 Taxis",
    "Amount": "50.00"
}

Following the documentation, I tried to do something like

{{#if this.Status = 'Success'}}
#00b300
{{else}}
#ff0000
{{/if}}

I found example only for boolean field.

My goal is to change the text color based on a field. What is the best way to do that?

Upvotes: 4

Views: 4165

Answers (2)

Vladutz
Vladutz

Reputation: 95

See the complete example below where if and equals are combined:

{{#if Status}}

    {{#equals Status "Success"}}
        do_something
    {{/equals}}

    {{#equals city "Failed"}}
        do_something
    {{/equals}}

{{else}}
    do_something
{{/if}}

Also check the other statements:

Conditional statements:
{{#if variable}}
{{#unless variable}}
{{#greaterThan variable value}}
{{#lessThan variable value}}
{{#equals variable value}}
{{#notEquals variable value}}
{{#and variable1 variable2}}
{{#or variable1 variable2}}

Looping statements:
{{#each hash}}

Upvotes: 0

larry
larry

Reputation: 41

Sendgrid doesn't allow to check strings like this Please modify code as below

{{#equals this.Status "Success"}}

Reference link for other conditions statements: https://sendgrid.com/docs/for-developers/sending-email/using-handlebars/#conditional-statements

Upvotes: 4

Related Questions