mjmlio / mjml

MJML: the only framework that makes responsive-email easy
https://mjml.io
MIT License
17.08k stars 960 forks source link

Suggestion: allow mj-include inside of mj-table #1346

Closed pawl-bb closed 6 years ago

pawl-bb commented 6 years ago

First of all - great work on MJML.

I have a table cell that's shared across multiple templates, but currently I need to copy the code to each of those tables since you can't mj-include within mj-table. It would be nice to be able to share that code to keep things more maintainable.

What would you think about allowing mj-include inside of mj-table? The included template wouldn't have any mj- tags, just <td>/<tr>/plain html.

ngarnier commented 6 years ago

Can you share the HTML table you want to include and the mj-text in which you want to include it? It should still be doable to include the table as a separate mj-text or mj-table before the mj-text in which you want to include it no?

pawl-bb commented 6 years ago

@ngarnier Sorry, typo in my original post. I actually want to mj-include within mj-table.

ngarnier commented 6 years ago

So you want to include for example only one or a few trs in a bigger table?

iRyusa commented 6 years ago

Hi,

When rebuilding MJML4, we decided that ending tags shouldn't never be parsed from the parser, implying that it won't allow any include inside it (mj-text/style/table/...).

It's a by design choice, here I think you would need some kind of templating language instead of mj-include

pawl-bb commented 6 years ago

@ngarnier Yup that's exactly it.

Original code:

        <mj-table>
          <tr style="border-bottom:1px solid #ecedee;text-align:left;padding:15px 0;">
            <th style="padding: 0 15px 0 0;">Year</th>
          </tr>
          <tr>
            <td style="padding: 0 15px 0 0;">1995</td>
          </tr>
        </mj-table>

New code:

        <mj-table>
          <tr style="border-bottom:1px solid #ecedee;text-align:left;padding:15px 0;">
            <th style="padding: 0 15px 0 0;">Year</th>
          </tr>
          <mj-include path="./last_row" />
        </mj-table>

@iRyusa Know if anyone has any examples of pre-mjml templating?

ngarnier commented 6 years ago

Yeah that sounds tricky because of what @iRyusa said, mj-table only takes HTML.

You could probably do what you want with something like https://pugjs.org/api/getting-started.html or https://handlebarsjs.com/ or any template language of your choice. Creating a workflow with Gulp could do the trick too (there's gulp-mjml package).

I'm closing as we can't do anything here.