繁体   English   中英

玉模板:nest mixin

[英]Jade template : nest mixin

在mixin下面

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中

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以及如何将其渲染为第一个输出。

谢谢

似乎它应该是可能的。 至少这里的人能够。

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

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'mixin的定义中调用'field'coinin。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM