Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to iterate array of objects in Sendgrid template? #221

Closed
ghost opened this issue Apr 11, 2016 · 142 comments
Closed

How to iterate array of objects in Sendgrid template? #221

ghost opened this issue Apr 11, 2016 · 142 comments
Labels
type: non-library issue API issue not solvable via the SDK

Comments

@ghost
Copy link

ghost commented Apr 11, 2016

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 } ]
@thinkingserious thinkingserious added type: question question directed at the library status: help wanted requesting help from the community labels May 21, 2016
@thinkingserious
Copy link
Contributor

Hello @sabapk,

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

@adamreisnz
Copy link
Contributor

is this supported yet by the templating engine?

@thinkingserious
Copy link
Contributor

@adamreisnz,

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

@thinkingserious
Copy link
Contributor

@adamreisnz,

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

@adamreisnz
Copy link
Contributor

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.

@eupharis
Copy link

eupharis commented Mar 9, 2017

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

@thinkingserious
Copy link
Contributor

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

@free4ride
Copy link

free4ride commented Apr 9, 2017

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

@thinkingserious
Copy link
Contributor

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

@davidhagg
Copy link

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

@stephengardner
Copy link

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.

@thinkingserious
Copy link
Contributor

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

@adamreisnz
Copy link
Contributor

adamreisnz commented May 17, 2017

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.

@thinkingserious
Copy link
Contributor

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
Copy link
Contributor

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

@psavard
Copy link

psavard commented May 26, 2017

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

Thanks ;)

@free4ride
Copy link

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

@thinkingserious
Copy link
Contributor

Thanks @free4ride, your vote has been added.

@gabzim
Copy link

gabzim commented May 31, 2017

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

@eupharis
Copy link

+1! Iterators would be awesome!!

@thinkingserious
Copy link
Contributor

@arg20, @eupharis,

Your votes have been counted, thanks!

@MaxShv
Copy link

MaxShv commented Jun 20, 2017

Any ETA on this? It is ridiculous that this feature hasn't been implemented yet. Right now we are generating the email body on the server and it is getting rejected by sendgrid API because it is over the substitute limit.

@etyp
Copy link

etyp commented Jun 20, 2017

@thinkingserious any update on this? We're likely to move off of Sendgrid in the coming week if there's no affirmative movement on it. We can't afford to compromise the quality of our emails because a standard feature like this isn't supported by a large service.

@thinkingserious
Copy link
Contributor

Hi @MaxShv, @etyp,

I have added your votes and passed this additional feedback to our product team.

I don't have any new insights into the progress on this, but once I do find that there is movement, I will update this thread.

With Best Regards,

Elmer

@9mm
Copy link

9mm commented Jun 25, 2017

The fact you don't have this is a complete a utter joke.

@thinkingserious
Copy link
Contributor

You vote has been added @9mm, thanks!

@futhr
Copy link

futhr commented Jul 17, 2017

Hi @thinkingserious, thanks for a great service, what is the progress of this? You would be so much more awesome if you can add e.g. Handlebars support without forcing your clients to use an external webhook service like Sendwithus.

Thanks

@ronneyramon
Copy link

I´m interest in this too!!!

@gferrin
Copy link

gferrin commented May 14, 2018

WTF is wrong with you guys. I wish I read this before signing up for SendGrid. How has it taken you OVER TWO YEARS to implement such a basic feature!

@ameesme
Copy link

ameesme commented May 14, 2018

We have decided to switch to Mailjet, which does support features like (multi-dimensional) looping, if-statements, variables and some functions for dynamically generating blocks, with a Node.js-wrapper on Github as well.

The development of this feature takes way too long.

@thinkingserious
Copy link
Contributor

Thanks for all of the additional votes to get this completed, we can't wait for this to be released also!

This feature is already in active development and if you would like to be added to the beta, please send an email to [email protected].

Thanks!

@adamreisnz
Copy link
Contributor

@thinkingserious and it's looking good! :)

@iBet7o
Copy link

iBet7o commented May 17, 2018

The turn of the corner seems too far away!

I'm waiting too

@miller-aaron
Copy link

+1 need this as well

@subratbasnet
Copy link

Definitely +1 - on the verge of switching to another provider just because of this feature.
I have emailed @ben-grid to see if we can have it enabled for our account.

@bcarradini
Copy link

We will also be emailing @ben-grid to get on this beta. +1

@giedriusr
Copy link

Can't believe it doesn't have such a basic feature.

@subratbasnet
Copy link

It looks like in the beta, this feature is now there under "transactional" templates. The old templates seems to have been renamed to "legacy"

How do I access this via API @ben-grid , do we have docs for this? The 3.0 API does not seem to have it.

Thanks

@dbalayan
Copy link

dbalayan commented Jun 8, 2018

+1
need this to migrate on SendGrid completely without any crutches!

@ben-grid
Copy link

Hey all,

I just wanted to give an update here. First of all, A BIG thank you to everyone who has participated in interviews and the beta program. Your feedback has been invaluable! Second, thank you to EVERYONE on this thread for your patience. I've read all of your comments and, candidly, your frustration is completely understandable. You've waited a long time for a very critical feature and I couldn't be happier that we are finally closing that gap.

If you don't have access already and need it, shoot me an email @ [email protected] to get into the beta. We'll also be rolling this out to ALL users just around the corner, and I'll update this thread soon with a firm date.

Thanks again, you all rock!

@TimoWestland
Copy link

Hi @ben-grid I've emailed you to get access to the beta but I'm not getting any replies. Is there any way we can get access to this asap? We would really like to use sendgrid as our e-mail engine but this is blocking us...

@loeklj
Copy link

loeklj commented Jul 3, 2018

@ben-grid same here 👍 Please let us know when we would be able to get Beta access.

@catamphetamine
Copy link

catamphetamine commented Jul 11, 2018

2 years and still not implemented.
People are hitting the 10000 limit which even lies about it because I made parameters less than 10000 bytes by splitting them in half and it still complains that "Substitutions are limited to 10000 bytes per personalization block".

@thinkingserious
Copy link
Contributor

Hello @catamphetamine,

This feature is hitting GA very shortly. If you would like beta access prior to that, please reach out to [email protected].

Thanks!

With Best Regards,

Elmer

@sendgrid-ryan
Copy link

Hey all! Great news––

Dynamic content for Transactional Templates is here!

This morning, our team publicly launched dynamic content for transactional templates. It is now available for all customers sending over v3 of our Mail Send API. Iterate over lists, handle conditionals and more, thanks to native support for a subset of Handlebars syntax!

More information can be found in our blog post announcement.

Documentation:

Thank you, on behalf of the entire SendGrid team, for all of the feedback throughout the beta program. 🙌🏻

@adamreisnz
Copy link
Contributor

Great news, good work team 💯

@dougdonohoe
Copy link

This dynamic template stuff is great. Nice work and great timing for us :-)

@token-appsolzone
Copy link

  {{#each attendee}}
    <table style="border: 1px solid #ccc;
box-shadow: 0 0 3px #000; font-size: 13px; font-weight: 600">
<tr>
      <td style="width:120px;">Attendee Name</td>
      <td>:</td>
      <td>{{attendeeName}}</td>
    </tr>
    <tr>
      <td style="width:120px;">Email</td>
      <td>:</td>
      <td>{{attendeeEmail}}</td>
    </tr>
    <tr>
      <td style="width:120px;">Phone</td>
      <td>:</td>
      <td>{{attendeePhone}}</td>
    </tr>

</table>
{{/each}}

data--
{
"attendee":[
{
"attendeeEmail":"[email protected]",
"attendeeName":"Token",
"attendeePhone":"12345678"
},
{
"attendeeEmail":"[email protected]",
"attendeeName":"Arnab",
"attendeePhone":"6483652"
},
{
"attendeeEmail":"[email protected]",
"attendeeName":"Musha",
"attendeePhone":"9735427"
}

    ]
}

@azizjawad
Copy link

Thanks, bro that was really helpful

@rastiehaiev
Copy link

Hi! Is there any way to have iteration inside iteration?

@token-appsolzone
Copy link

yes nested iteration is possible
{{#each first array}}

{{#each innerarray}}
your html or data presentation
{{/each}}

{{/each}}

@StavoG
Copy link

StavoG commented Oct 12, 2021

Thanks a lot for this. It helped me so much

@sourabhCofoundry
Copy link

Hello, token-appsolzone Please help me Please create send grid code for this data
{
"publisResult": [
{
"key": {
"SearchTerm": "flower"
},
"data": [
{
"PublisImgUrl": "https://picsum.photos/200/300.jpg",
"Name": "Jhon",
"Title": "gardenflowershop",
"Description": "OnlineFlower"
},
{
"PublisImgUrl": "https://picsum.photos/200",
"Name": "Tommy",
"Title": "weddings",
"Description": "Wedding"
}
]
},
{
"key": {
"SearchTerm": "Pizza"
},
"data": [
{
"PublisImgUrl": "https://picsum.photos/200/300",
"Name": "Harry",
"Title": "benny-drinnon.com",
"Description": "TAMELAC"
},
{
"PublisImgUrl": "https://picsum.photos/200/300",
"Name": "Roma",
"Title": "benny",
"Description": "Michelle"
}
]
}
]
}

@sourabhCofoundry
Copy link

Any update on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: non-library issue API issue not solvable via the SDK
Projects
None yet
Development

No branches or pull requests