conficient / BlazorTemplater

A library that generates HTML (e.g. for emails) from Razor Components
Apache License 2.0
146 stars 16 forks source link

Conditionals being lost in render #34

Closed hopfrogpoe closed 1 year ago

hopfrogpoe commented 1 year ago

I'm trying to render a .razor file (email template) that contains conditionals like

<!--[if mso]>
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td width="50%" valign="top">
<![endif]-->

but they don't survive through the render. Is this something that can be fixed or is there a flag to set that already does this? Any help would be great.

conficient commented 1 year ago

It appears to be the default behaviour of the Blazor rendering engine. I found this StackOverflow article which also suggests a workaround using MarkupString. Suggest you try this:

@((MarkupString)"<!--[if mso]-->")
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td width="50%" valign="top">
@((MarkupString)"<!--[endif]-->")

I'm adding a test for this to check this behaviour going forward.

conficient commented 1 year ago

All seems to work fine with the MarkupString workaround.

hopfrogpoe commented 1 year ago

Thank you for that! Not sure how I didn't find that in my searches but I appreciate it.