Mandrill-dotnet icon indicating copy to clipboard operation
Mandrill-dotnet copied to clipboard

Sending Arrays to email templates

Open loulv opened this issue 10 years ago • 6 comments

In recent Mandrill blog post they describe how their handlebars based templates can easily process arrays. Can support for passing an array as a merge var be added to this library?

http://blog.mandrill.com/handlebars-for-templates-and-dynamic-content.html

loulv avatar Feb 15 '15 10:02 loulv

Great, It was best San Valentine gift a full source code sample with this API Client C#

kiquenet avatar Feb 15 '15 10:02 kiquenet

Is there an example for showing how to use pass an array of items in? I need the template to iterate items (example: order summary showing the items a user ordered) but the TemplateContent.content field only accepts strings instead of lists/arrays/etc.

mellodev avatar Apr 30 '15 17:04 mellodev

Does this example help?

https://github.com/shawnmclean/Mandrill-dotnet/blob/master/tests/IntegrationTests/Messages/SendTemplateTests.cs#L36

shawnmclean avatar May 04 '15 07:05 shawnmclean

No I don't think that's what loulv asked for. He means something like this: http://stackoverflow.com/a/29401083/297183 See that small code change, this supports dynamic, so it also supports arrays of strings to support objects to iterate over.

rodyvansambeek avatar May 13 '15 19:05 rodyvansambeek

@shawnmclean Any plans to implement what @rodyvansambeek is referring to? Having the TemplateContent object support dynamic content would be very useful. I'm trying to send a template email and have it iterate over an array of strings or objects.

robfarmergt avatar Aug 14 '15 19:08 robfarmergt

@shawnmclean It actually seems like the handlebars templates are rendered using the global and recipient merge variables. I was successfully have to have a template render an array of objects like:

message.AddRecipientVariable("[email protected]", "lines", new object[] {
                new {
                    text = "one"
                },new {
                    text = "two"
                } });

robfarmergt avatar Aug 14 '15 20:08 robfarmergt