sendgrid / email-templates

A repository of common email templates to use and modify to your heart's content.
https://sendgrid.com
MIT License
818 stars 988 forks source link

Can not use formatDate helper inside table #93

Open adokarasev opened 2 years ago

adokarasev commented 2 years ago

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

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

tfuchs1 commented 2 years ago

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.

AnastasiaBlack commented 2 years ago

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.

mrlubos commented 2 years ago

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?

mrlubos commented 2 years ago

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

adrianmxb commented 1 year ago

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

thomas-schweich commented 1 year ago

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.

goleafs commented 1 year ago

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.

carfarmer commented 1 year ago

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.

bentrynning commented 1 year ago

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.

MarianaKWork commented 1 year ago

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

tfuchs1 commented 1 year ago

@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.

TmarcAHX commented 11 months ago

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

chinmayv commented 7 months ago

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

These were the issues:

EStallings commented 6 months ago

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.

daweimau commented 4 months ago

Workaround (non-css)

The issue seems to be caused by the auto generated plaintext.

Here is an example of a dynamic template affected by this issue

<html>
<body>
  <div>
    <h1>Order history</h1>
    <table>
    {{#each user.orderHistory}}
        <tr>
            <td>
                <p>You ordered {{this.item}} on {{formatDate this.date "DD/MM/YYYY"}}</p>
            </td>
        </tr>
    {{/each}}
    </table>
  </div>
</body>
</html>

In the template editor, if we disable the sendgrid setting: AUTOMATICALLY CREATE PLAIN TEXT VERSION, we can now see the plaintext that was generated:

*************
Order history
*************

{{#each user.orderHistory}} {{/each}}

You ordered {{this.item}} on {{formatDate this.date "DD/MM/YYYY"}}

The each loop in this generated plaintext is broken.

Manually fixing the plaintext fixes the template and cures the behaviour.

I notice that the each loop breaks in other circumstances too, but doesn't necessarily cause the template to drop. I don't know why it works sometimes. But I can confirm this a way to repair an affected template.