sendgrid/email-templates

Can not use formatDate helper inside table

adokarasev opened this issue · 15 comments

Actual Behaviour

Template should be rendered.

Expected Behaviour

Test email is not received. It's hard to say what is wrong. But when I replace table with ul or just p tags it works ok.

Steps to reproduce it

  • Create email template
<html>
<body>
<table>
<tbody>
{{#each meetings}}
<tr>
    <td>{{title}}</td>
    <td>{{formatDate startAt "h:mm"}}</td>
    <td>{{formatDate endAt "h:mm"}}</td>
</tr>
{{/each}}
</tbody>
</table>
</body>
</html>
  • Set test data
{ 
    "meetings": [
        {
            "title": "meeting 7",
            "startAt": 1633023600,
            "endAt": 1633023600
        },
        {
            "title": "meeting 8",
            "startAt": 1633023600,
            "endAt": 1633023600
        },
        {
            "title": "meeting 8",
            "startAt": 1633023600,
            "endAt": 1633023600
        }            
    ]
}
  • Editor shows data in the table.
  • Send test email
  • No email received

If you replace table with list it works fine. If you delete formatDate helper it also works

My workaround for that is that I use a div with display set to table-cell:
<tr><td>Some Data</td><div style="display:table-cell"> {{ formatDate this.timestamp "YYYY-MM-DD" }} </div></tr>

It's not displaying correctly in the editor but the rendered email looks good.

We have faced the same issue. The handlebar seems to break rendering when used in a loop inside a table tag . @tfuchs1 , thank you, your workaround did help.
But it would be great if there is a fix for the tables to use formatDate with them as well.

Ugh, this is very much an issue @adokarasev, and thanks @tfuchs1 for finding a workaround! I can confirm the workaround fixes the issue, but feels dirty and in my case not feasible due to using automated template generator.

@JenniferMah @shwetha-manvinkurke @eshanholtz @thinkingserious wondering if we can get any eyes on this repository as the issues don't seem to be monitored?

There's another issue with using loops, and that's if you have a JSON like this

{
    "loop": [
        {
            "foo": "Foo.loop"
        }
    ],
    "foo": "Foo.root",
}

and you reference loop[0].foo inside the loop as this.foo, you guessed it, you will get "Foo.root." It appears correctly in the editor, but what you see doesn't get sent

Looks like this is still an issue, any update on that one?

Hello, this bug still repros in March of 2023. If we could at least get some kind of indication that this is what's happening in the error message or in the documentation, it would be really helpful. I only found this issue after multiple days of troubleshooting. It's extremely difficult to diagnose because the template renders just fine within the editor preview, but when you attempt to send an email it fails completely, and all you get is a message that says "this message could not be sent", which is super unhelpful.

If there is some way this issue could even just be linked in the error message it would've saved loads of time. Ideally, maybe it can be fixed? I don't understand how/why this error would occur, so I have no idea how complex it would be. It was very surprising to me when I found that the preview in the editor uses a different rendering system than the actual emails when they're sent. Are there any plans to unify them? It makes bugs 100x more confusing when you don't even know if what you're looking at is what will actually be in the email.

It seems like there are several relatively simple ways this issue could at least be partially addressed as opposed to just leaving this issue open indefinitely.

Hit this today, and would agree with comment above. Extremely frustrating to have no clue why the email works in the editor but fails when sending with a very generic error about template rendering. At least put a warning in the documentation that formatDate can not be used with #each.

Just ran into this as well. Would love to get this fixed. Took a while to figure out why my template was rendering but not sending. The only error I see in the Activity logs is a generic "Template render failure" with no indication of why.

Same her, for me formatDate does not work in the email template at all. When i take {{formatDate date "DD.MM.YYYY"}} out of the template email is being sent.

@tfuchs1 Thanks for the fix! Did you still have this in a parent table? Or did you take it out of the table?

@MarianaKWork Yes we had this inside of a parent table and it worked for the Browser-based Email Clients, but not for Desktop Clients like Apple Mail (the table view was broken/not formatted correctly). Therefore we ended up not using the formatDate function at all and instead doing the date conversion in the backend, and sending it with the payload.

Pretty sad an issue that is this simple is still open after nearly 2 years.

This is still an issue. Instead of using formatDate I inserted the variable from data.

These were the issues:

  • It worked in preview but when sending a test message it failed.
  • In activity, it just showed that email dropped and that This email could not be sent
  • I had to go check the network tab in developer tools to see the response from API call. There it showed that error was "Template Render Failure".

I can confirm that this is still an active issue, and that the user experience of finding out what is happening is unintuitive and frustrating. I had to use trial-and-error to figure out what was failing.

Obviously, the best would be for this to work. In the mean time, I guess I'll pre-format all data for sendgrid.