How to iterate array of objects in Sendgrid template?
Mandrill provides support for Handlebars template and so looping is supported. As I read, Sendgrid doesnot support each like directive. So how do the sendgrid users tackle this shortcoming?
I want to loop through the products, as shown in below object.
products:
[ { name: 'VEEBA SWEET CHILLI SAUCE 1KG',
qty: 2,
price: 145,
packSize: '1 KG',
itemSubTotal: 290,
comments: null },
{ name: 'Chilled French Fries',
qty: 1,
price: 85,
packSize: '1 KG',
itemSubTotal: 85,
comments: null } ]
Hello @sabapk,
Please open a ticket at https://support.sendgrid.com. Thanks!
is this supported yet by the templating engine?
@adamreisnz,
I'm checking with our product team for an update, thanks!
@adamreisnz,
This is on our radar for implementation, but there is no estimate on timeline yet.
Ok thanks for the update. I guess a work around would be to generate the looped HTML manually and pass that in as a substitution. Crude, but it would work.
@thinkingserious I am subscribed to this issue. Is there another way I could subscribe for notifications about iterator implementation in sendgrid templates?
Hello @eupharis,
Please make sure the email you have in your SendGrid account settings is up to date. We send product announcements to that email address.
Thanks!
Elmer
Hi @thinkingserious What is status of this issue? When is it coming live?
Hi @free4ride,
There is still no estimate on timeline yet.
The best option to be notified of any updates on this issue is to make sure the email you have in your SendGrid account settings is up to day.
Thanks!
Elmer
As @adamreisnz commented, sending the array in as a HTML might work, however we are experiencing problems with the substitutions being too large, exceeding 10000 bytes
Sendgrid, I thought, was a pretty good alternative to Mandrill.
No looping?
That's actually ridiculously surprising from such a large service....
It's impossible to even create a checkout order success form, because you need to loop through the items purchased and display them.
Oh well, another one down.
Hello @stephengardner,
Have you tried using substitutions with our templates? Check this out.
If that does not fit your need, let me know and I'll try to figure out how to help you achieve the results you need.
Thanks!
With Best Regards,
Elmer
Substitutions don't work for listing a table of purchased products for example, because they can only replace one value, and not an array of values, let alone an array of objects with more detailed values.
What we need is support to loop through products and have a template for each product that then gets repeated depending on how many products you supply for the substitution.
The only way around it is kind of half-baked -- you'd have to generate the HTML on the server, and send that whole chunk of HTML as a single substitution. Clearly that is not ideal as you then have part of the layout sitting in server side code instead of nicely in the online template where designers can edit it.
I do agree that this is a major item that's preventing us from using templates as well. As such, we have templates on our server and process them there using handlebars, which does support looping, if statements, etc. We then just send the entire HTML out as mail body, which is a bit of a waste of resources.
Thanks @adamreisnz,
I have reached out to the product team that owns this functionality. I will update this thread when I learn more.
With Best Regards,
Elmer
Hi @stephengardner, @adamreisnz,
Your votes have been added to give this feature higher priority for implementation.
Please make sure the email you have on file for your account is up to date, that is how we would notify you of the implementation of the feature.
With Best Regards,
Elmer
I would like to vote up this feature too. This is a must for you system.
Thanks ;)
Completely agree. Up-vote from me and my team! Please add this feature asap.
Thanks @free4ride, your vote has been added.
+1, I was surprised to find this is not implemented yet, I assumed iterating would work. Add my vote please.
+1! Iterators would be awesome!!