【问题标题】:in Jade, how I can output the contents of an `extends` block inside of a mixin?在 Jade 中,如何在 mixin 中输出“extends”块的内容?
【发布时间】:2013-09-09 18:48:41
【问题描述】:

如何在 mixin 中输出 extends 块的内容?

这是一个简化的例子:

mixins.jade

mixin form()
  form
    block

layout.jade

include mixins.jade

body
  +form
    block content

somepage.jade

extends layout
block content
  input(type=text)

这里我想实现:

<form>
  <input type="text"></input>
</form>

但目前我得到的只是:

<form></form>

【问题讨论】:

  • 我创建了this pull request 来添加一个失败的测试来证明这个问题。
  • 我想确认当 layout.jade 中不涉及 include 并且 mixin 只是内联写入时问题仍然存在。

标签: block pug mixins template-inheritance


【解决方案1】:

尝试以下方法:

layout.jade

doctype 5
  head 
    title "Title"
  body
    block content
      include mixins.jade
      +form
        block

SomePage.jade

extends layout
block content
  input(type=text)

【讨论】:

  • 这不起作用。我在我的问题上添加了一条评论,说明了不涉及包含时的问题。
  • 这很奇怪,我使用它在本地工作。今晚晚些时候我会检查它并尝试复制你的错误然后修复它。
【解决方案2】:

在我创建了GitHub issue 并提交了failing spec 之后,identified as a bug 不起作用。

根据this pull request,现在可以执行我在原始问题中描述的操作,但as stated,目前仅适用于 Jade 的开发分支,并将成为下一个版本的一部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-11
    • 1970-01-01
    • 2012-03-14
    • 2013-04-20
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多