I am writing application using Nodejs/express/hbs/handlebars.
I try to send e-mails to user, after purchase, with receipt. It should be just simple text message, with invoice entries and total value.
Sending email works well, and I can render simple values like {{buyers_email}}
, but when comes to using {{#each }} ... {{/each}}
- it doesn't render it, it just prints it literally to email's content.
It is even weirder, because in normal pages (like index.hbs), the {#each}
is used, and it works well.
Here goes the code:
server.coffee
sendReceipt = (buyers_email) ->
products = [
{ name: 'Product1', name: 'Joan' }
{ name: 'Product2', name: 'Cesar' }
]
mailer.send
host: xxx
port: xxx
authentication: 'login'
username: xxx
password: xxx
domain:xxx
from: xxx
to: buyers_email
subject: xxx
template: 'views/email-receipt.hbs'
data:
products: products
some_key: "some value"
, (err)-> {}
email-receipt.hbs
<p>{{some_key}}</p>
{{#each products}}
<p>product</p>
{{/each}}
and the result is:
some_value
{{#each products}} product {{/each}}
What can cause such a behaviour?