sendgrid-nodejs icon indicating copy to clipboard operation
sendgrid-nodejs copied to clipboard

How to iterate array of objects in Sendgrid template?

Open ghost opened this issue 10 years ago • 142 comments

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 } ]

ghost avatar Apr 11 '16 06:04 ghost

Hello @sabapk,

Please open a ticket at https://support.sendgrid.com. Thanks!

thinkingserious avatar Jun 28 '16 22:06 thinkingserious

is this supported yet by the templating engine?

adamreisnz avatar Jan 09 '17 00:01 adamreisnz

@adamreisnz,

I'm checking with our product team for an update, thanks!

thinkingserious avatar Jan 26 '17 00:01 thinkingserious

@adamreisnz,

This is on our radar for implementation, but there is no estimate on timeline yet.

thinkingserious avatar Jan 26 '17 00:01 thinkingserious

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.

adamreisnz avatar Jan 26 '17 05:01 adamreisnz

@thinkingserious I am subscribed to this issue. Is there another way I could subscribe for notifications about iterator implementation in sendgrid templates?

eupharis avatar Mar 09 '17 23:03 eupharis

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

thinkingserious avatar Mar 15 '17 17:03 thinkingserious

Hi @thinkingserious What is status of this issue? When is it coming live?

free4ride avatar Apr 09 '17 13:04 free4ride

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

thinkingserious avatar Apr 10 '17 22:04 thinkingserious

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

davidhagg avatar May 02 '17 11:05 davidhagg

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.

stephengardner avatar May 17 '17 06:05 stephengardner

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

thinkingserious avatar May 17 '17 17:05 thinkingserious

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.

adamreisnz avatar May 17 '17 18:05 adamreisnz

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

thinkingserious avatar May 17 '17 18:05 thinkingserious

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

thinkingserious avatar May 17 '17 19:05 thinkingserious

I would like to vote up this feature too. This is a must for you system.

Thanks ;)

psavard avatar May 26 '17 18:05 psavard

Completely agree. Up-vote from me and my team! Please add this feature asap.

free4ride avatar May 26 '17 19:05 free4ride

Thanks @free4ride, your vote has been added.

thinkingserious avatar May 30 '17 21:05 thinkingserious

+1, I was surprised to find this is not implemented yet, I assumed iterating would work. Add my vote please.

gabzim avatar May 31 '17 18:05 gabzim

+1! Iterators would be awesome!!

eupharis avatar May 31 '17 19:05 eupharis