【问题标题】:Jade, mixin && htmlJade, mixin && html
【发布时间】:2011-12-13 13:56:59
【问题描述】:

我正在为 node.js 使用玉。我有 1 个 mixin(测试):

mixin some( field, field2 )
  .field!= field
  .field2!= field2

我需要在mixin中加入一些html代码,例如:

#test
  some( a( href='http://test' )='test', span.description=description )

我想要那个:

<div id="test">
  <div class="field"><a href="http://test">test</a></div>
  <div class="field2"><span class="description">bla bla bla</span></div>
</div>

我该怎么做?现在我只知道一个丑陋的决定:

#test
  - var field = '<a href="http://test">test</a>';
  - var field2 = '<span class="description">' + descriptions + '</span>';
  mixin some( field, field2 )

对不起,我的英语不好:)

【问题讨论】:

    标签: node.js mixins pug


    【解决方案1】:

    看起来您当前的解决方案是唯一的方法。 mixin 的参数是 javascript 表达式,而不是玉元素。

    【讨论】:

      【解决方案2】:

      其实你也可以将 Jade 标记传递给 mixin

      mixin article(title)
        .article
          .article-wrapper
            h1= title
            if block
              block
            else
              p No content provided
      
      +article('Hello world')
      
      +article('Hello world')
        p This is my
        p Amazing article
      

      我知道这个问题已经很老了。留下回复,以便其他人可能会发现它有帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-15
        • 2013-09-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-11
        • 1970-01-01
        • 2015-06-30
        相关资源
        最近更新 更多