Jade, mixin && html

5

我正在使用node.js的jade。我有1个mixin(test):

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

我需要将一些HTML代码放入mixin中,例如:

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

I want that:

<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 )

抱歉,我的英语不太好 :)
2个回答

1
实际上,您也可以将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

我知道这个问题很旧了。留下回复,希望能对其他人有所帮助。


1

看起来你目前的解决方案是唯一的方法。mixins 的参数是 JavaScript 表达式,而不是 Jade 元素。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接