Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not use formatDate helper inside table #93

Open
adokarasev opened this issue Oct 6, 2021 · 15 comments
Open

Can not use formatDate helper inside table #93

adokarasev opened this issue Oct 6, 2021 · 15 comments

Comments

@adokarasev
Copy link

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

@tfuchs1
Copy link

tfuchs1 commented Nov 10, 2021

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
Copy link

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
Copy link

mrlubos commented Apr 26, 2022

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
Copy link

mrlubos commented Apr 26, 2022

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
Copy link

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

@thomas-schweich
Copy link

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
Copy link

goleafs commented Mar 29, 2023

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
Copy link

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
Copy link

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
Copy link

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

@tfuchs1
Copy link

tfuchs1 commented Apr 17, 2023

@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
Copy link

TmarcAHX commented Sep 5, 2023

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

@chinmayv
Copy link

chinmayv commented Jan 28, 2024

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

@EStallings
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests