我可以用 Pug 模板化一组公共属性吗?

Can I template a group of common attributes with Pug?

我正在为 HTML 电子邮件设置模板,我的许多表格如下所示:

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

为了节省时间和提高可读性,我想如果我能写得更像这样就更好了:

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

以上输出 tableAttrs="tableAttrs",如果插值则为 #{="#{" tableAttrs="tableAttrs" }="}"

我也试过一个简单的 mixin,我没想到它会支持嵌套,并没有让我失望:

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

+table()
  tbody...

如果我的目标可能或不可能,我很想知道!

如果包含 block 语句,Mixins 确实支持嵌套。

混合:

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

用法:

+table()
  tr
    td text

结果:

<table align="center" border="0" cellpadding="0" width="100%">
  <tr>
    <td>text</td>
  </tr>
</table>