3

I am trying to display dynamic content by using the mandrill template api in a node project.

I have followed the docs and looked at plenty of examples, and for the most part can get things working.

However, when I try to access properties of an object that I pass through the api in the mandrill template, it does not display anything.

Here is my mandrill template (using handlebars):

<p>{{greeting}} {{person.firstName}},</p>
<p>{{greeting}} {{person.0.firstName}},</p>
<p>Your location is {{person.location}}.</p>

Now, the greeting does display the value passed in the global_merge_vars part. But the properties for the person object do not get displayed, as if they are undefined.

Here is part of the json being sent:

var greeting = "Hello ";
var person = {firstName:"testfname",location:"testlocation"};

var globalMergeVars = [
    {"name": "greeting","content":greeting},
    {"name": "person","content": person},
];

Am I not passing the object correctly or naming the 'name' property correctly in the api call? I have tried a bunch of different things. I know that I could create multiple vars inside the globalMergeVars object instead of passing the entire person object, however I have a lot more properties attached to the person object.

I have also successfully used an each loop for an array of items and that all gets displayed correctly.

Thanks.

3
  • Did you find an answer to this @mrpetem? I've asked a similar question here stackoverflow.com/questions/37071092/… before coming across yours...
    – SRack
    May 6, 2016 at 13:22
  • If it's useful for you, or anyone else visiting here, I've found the solution through my own question when using Rails, here: stackoverflow.com/questions/37071092/….
    – SRack
    May 6, 2016 at 13:38
  • having same issue. Except, I can access some properties at the same llevel, but not others. looks like the ones failing to show up are the ones in camel case Mar 22, 2019 at 23:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.