0

我在使用此包含的所有模板中都收到此错误:

{% include '../public/templates/header.html' %}

有谁知道可能出了什么问题?

Error: UNKNOWN, unknown error '//../public/templates/header.html'
at Object.fs.openSync (fs.js:427:18)
at Object.fs.readFileSync (fs.js:284:15)
at getSingle (C:\project\node_modules\swig\lib\swig.js:152:19)
at get (C:\project\node_modules\swig\lib\swig.js:159:7)
at Object.exports.compileFile (C:\project\node_modules\swig\lib\swig.js:177:7)
at eval (eval at createRenderFunc (C:\project\node_modules\swig\lib\swig.js:44:10), :13:22)
at Object.eval (eval at createRenderFunc (C:\project\node_modules\swig\lib\swig.js:44:10), :15:3)
at Object.template.render (C:\project\node_modules\swig\lib\swig.js:111:21)
at C:\project\node_modules\swig\lib\swig.js:189:17
at Function.exports.swig.render (C:\project\node_modules\consolidate\lib\consolidate.js:245:14)
4

1 回答 1

0

看起来您正在使用严重过时的 Swig @v0.14.0。整个引擎针对 v1.0.0 进行了重写,带来了使用相对路径的能力。此功能以前不存在,因此您始终必须使用相对于root.

如果您继续使用 v0.14.0,假设您的root == './public/templates'或类似的:

{% include '/header.html' %}

但是,出于兼容性和支持目的,我强烈建议更新到最新版本 Swig @~1.2。

于 2013-12-11T16:22:35.033 回答