4

在这里遇到一个奇怪的问题。我有一个非常基本的玉/哈巴狗包括在这里:

extends base.pug

block vars
    - var title = 'Home'

block body
    header
        include ./includes/header.pug

快速说明,仅使用 extends base(没有扩展名)是行不通的。但是这个包含给出了以下错误:

TypeError: Cannot read property 'replace' of undefined
   at before (/var/node/website/node_modules/pug-linker/index.js:104:48)
   at walkAST (/var/node/website/node_modules/pug-walk/index.js:13:26)
   at /var/node/website/node_modules/pug-walk/index.js:21:16
   at Array.map (native)
   at walkAST (/var/node/website/node_modules/pug-walk/index.js:20:29)
   at walkAST (/var/node/website/node_modules/pug-walk/index.js:33:21)
   at /var/node/website/node_modules/pug-walk/index.js:21:16
   at Array.map (native)
   at walkAST (/var/node/website/node_modules/pug-walk/index.js:20:29)
   at /var/node/website/node_modules/pug-walk/index.js:21:16
   at Array.map (native)
   at walkAST (/var/node/website/node_modules/pug-walk/index.js:20:29)
   at applyIncludes (/var/node/website/node_modules/pug-linker/index.js:102:10)
   at link (/var/node/website/node_modules/pug-linker/index.js:21:9)
   at compileBody (/var/node/website/node_modules/pug/lib/index.js:84:11)
   at Object.exports.compile (/var/node/website/node_modules/pug/lib/index.js:164:16)

但将其更改为:

extends base.pug

block vars
    - var title = 'Home'

block body
    header
        include ./includes/header.jade

工作得很好。header.jade 和 header.pug 的内容完全一样,所以我在这里有点困惑。一些帮助将不胜感激。

谢谢,

PS:搜索确实显示:https ://github.com/pugjs/pug-linker/issues/13 - 似乎是一个错误,但不确定这是怎么回事。

4

2 回答 2

4

所以看起来哈巴狗还没有准备好迎接黄金时段!期待它什么时候出现,但是使用jade代替pug可以解决问题,只需将所有内容重命名为.jade.

于 2016-04-28T00:43:26.470 回答
0

从 Jade 到 Pug 的重大变化之一是您不能再插入变量。您曾经能够(并鼓励)#{something}在另一个字符串中使用,但现在鼓励您使用常规 JavaScript 变量。

例如,这个

a(href="#{link}")
a(href='before#{link}after')

现在应该变成

a(href=link)
a(href=`before${link}after`) //(on Node.js/io.js ≥ 1.0.0)
a(href='before' + link + 'after') //(everywhere)

来源:跟踪重大更改的问题

于 2016-05-11T09:35:29.870 回答