2013-07-01 68 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'混合。