brack3t / Djrill

[INACTIVE/UNMAINTAINED] Djrill is an email backend and new message class for Django users that want to take advantage of the Mandrill transactional email service from MailChimp.
BSD 3-Clause "New" or "Revised" License
319 stars 64 forks source link

How to use handlebars loops with Djrill #92

Closed kevgathuku closed 9 years ago

kevgathuku commented 9 years ago

Hi, I am having some trouble with inserting some dynamic content in my templates. I am trying to pass multiple objects to the template in order to use the for loops feature in Mandrill templates. I followed the examples and I am not able to pass multiple elements in the merge vars. This is my attempt so far:

msg.merge_vars = {'users': []}
for user in user_list:
            msg.merge_vars['users'].append(
                {
                    'name': user.first_name,
                    'role': user.role,
                    'id': user.id
                })

The corresponding template has a handlebars for loop that iterates over the users and displays the info.

What would be the best way to implement passing multiple elements to the template under a single key? Thanks in advance.

medmunds commented 9 years ago

I think you might be mixing up Mandrill's global_merge_vars and merge_vars. You probably want _global__merge_vars for what you've written. But if you do want to use merge_vars, those need to be set per-recipient. See the example in the Djrill docs for examples of both.

kevgathuku commented 9 years ago

Thanks. Using global_merge_vars fixed it.