2013-07-01 67 views
3

下面混入玉模板:巢混入

mixin form(title, action) 
    legend title 
    form.form-horizontal(method='post', action=action) 
     label Name: 
     input(type='text',name=Name,id=Name) 

呈现到

<legend>title</legend> 
<form method="post" action="save" class="form-horizontal"> 
    <label>Name:</label> 
    <input type="text"/> 
</form> 

现在,我中抽取的标签和场到另一个混入

mixin form(title, action) 
    legend title 
    form.form-horizontal(method='post', action=action) 

mixin field(name) 
    label #{name}: 
    input(type='text',name=name,id=name) 

使用
mixin form("xxxx", "save") 
    mixin field('Name') 

这给了错误

>> Line 1209: Unexpected string 
Warning: Jade failed to compile test.jade. Use --force to continue. 

是可以嵌套的mixin和如何使它呈现为第一输出。

谢谢

回答

1

似乎应该有可能。至少这里的人能够做到。

https://github.com/pugjs/pug/issues/1103

+2

这个人从链接是非常简洁,但他是对的。其实我花了一些时间试图弄清楚他的意思,所以也许这对别人有用。 **您必须在包含mixin的声明结束时添加块声明。** –

+0

您是否有代码示例? –

+0

我已经不再混入混混了,但我认为你必须像奥斯卡所说的那样最后加上“块”。像链接节目一样,但只有一次。 https://github.com/jadejs/jade/issues/1693 – Avec

1
mixin field(name) 
    label #{name}: 
    input(type='text',name='#{name}',id='#{name}') 

mixin forms(title, action, name) 
    legend #{title} 
    form.form-horizontal(method='post', action='#{action}') 
    block 
    +field(name) 

测试呼叫

+forms('*TheTitle*', '*TheAction*' , '*TheName*') 

呈现

<legend>TheTitle</legend> 
<form method="post" action="TheAction" class="form-horizontal"></form> 
<label>TheName:</label> 
<input type="text" name="TheName" id="TheName"/> 

必须分别定义mixins,然后在'forms'混合的定义中调用'field'混合。