1

I'm setting up templates for HTML emails, and many of my tables look like this:

table( align='center', border='0', cellpadding='0', cellspacing='0', width='100%' )

To save time and improve readability, I thought it would be sweet if I could write something more like this:

- var tableAttrs = "align='center', border='0', cellpadding='0', cellspacing='0', width='100%'"
table( tableAttrs )

The above outputs tableAttrs="tableAttrs", or #{="#{" tableAttrs="tableAttrs" }="}" if interpolated.

I've also tried a simple mixin which I did not expect to support nesting, and was not disappointed:

mixin table()
  table( align='center', border='0', cellpadding='0', cellspacing='0', width='100%' )

+table()
  tbody...

If my goal is possible or not possible, I'd love to know!

1 Answer 1

1

Mixins do support nesting if you include a block statement.

Mixin:

mixin table()
  table(align='center', border='0', cellpadding='0', cellspacing='0', width='100%')
    if block
      block

Usage:

+table()
  tr
    td text

Result:

<table align="center" border="0" cellpadding="0" width="100%">
  <tr>
    <td>text</td>
  </tr>
</table>
1
  • Just right, thank you! Did I miss this in the docs or something?
    – Frish
    Commented Feb 22, 2019 at 5:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.