如何在彼此之间包含两个NJK模板?

时间:2019-01-09 12:33:44

标签: node.js express nunjucks

在这种情况下,我有三个模板:

1)主页

2)模态按钮

3)过滤器表单

(2)中包含过滤表单(1)中包含 Modal Butto n >!

但是,如果我从(2)中删除(3),我从 NJK文件夹中遇到了层次结构问题,错误..但是路径是正确的,我意识到它最终从我的include main中创建了一个位置,该位置是(1)中的(2) ...

路径

1) app\backend\src\views\pages\home.njk

2) app\backend\src\views\templates\buttons\modals\filter.njk

3) app\backend\src\views\templates\forms\filters\global.njk

主页中包含模态按钮:

{% include '../templates/buttons/modals/filter.njk' %} 确定

模态按钮中过滤器形式的包含:

{% include '../templates/forms/filters/global.njk' %} 错误

错误:

Template render error: (C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\app\backend\src\views\pages\home.njk)
  Template render error: (C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\app\backend\src\views\templates\buttons\modals\filter.njk)
  Error: template not found: C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\app\backend\src\views\templates\buttons\templates\forms\filters\global.njk
    at Object._prettifyError (C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\nunjucks\src\lib.js:36:11)
    at C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\nunjucks\src\environment.js:547:19
    at eval (eval at _compile (C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\nunjucks\src\environment.js:617:18), <anonymous>:20:11)
    at C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\nunjucks\src\environment.js:555:11
    at eval (eval at _compile (C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\nunjucks\src\environment.js:617:18), <anonymous>:14:11)
    at createTemplate (C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\nunjucks\src\environment.js:279:11)
    at next (C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\nunjucks\src\lib.js:282:7)
    at handle (C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\nunjucks\src\environment.js:313:11)
    at C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\nunjucks\src\environment.js:323:9
    at next (C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\nunjucks\src\lib.js:280:7)
    at Object.asyncIter (C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\nunjucks\src\lib.js:286:3)
    at Environment.getTemplate (C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\nunjucks\src\environment.js:305:9)
    at eval (eval at _compile (C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\nunjucks\src\environment.js:617:18), <anonymous>:13:5)
    at fn (C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\a-sync-waterfall\index.js:26:24)
    at C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\a-sync-waterfall\index.js:66:22
    at executeSync (C:\Users\THIAGOSAAD\Documents\DEVELOPMENT\NEORIS\ALIANSCE\aliansce-app-analyticals-panel\node_modules\a-sync-waterfall\index.js:8:15)

1 个答案:

答案 0 :(得分:0)

尝试在初始化nunjucks.configure(['../views/templates','../views/pages'], [opts]);上设置nunjucks-path,并仅使用本地路径{% include "forms/filters/global.njk" %}