Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sendgrid handlebar template array length

I'm trying to fetch length of an array but it seems length only exists for conditionals.

Data:

{
    "array": ["a", "b", "c"]
}

in sendgrid template:

{{array.length}}

and nothing is rendered in the email (preview renders it correctly).

Is there a workaround for this?

like image 947
maslak Avatar asked Oct 15 '25 07:10

maslak


1 Answers

it looks like you can use the greaterThan tag

Example from Sendgrid docs:

<p>
Hello Ben!
{{#greaterThan (length cartItems) 0}}
 It looks like you still have some items in your shopping cart. Sign back in to continue checking out at any time.
{{else}}
 Thanks for browsing our site. We hope you'll come back soon.
{{/greaterThan}}
</p>
like image 110
MorenoMdz Avatar answered Oct 17 '25 22:10

MorenoMdz