2017-08-25 49 views
0

我使用的自动化工作流程与一饮而尽建立基于此nunjucks模板HTML和CSS:https://github.com/uxmoon/automate-workflow使用includeData标签与nunjucks模板化

,现在我想包括存储在文件中访问它们在JSON数据我组件。有一个名为“includeData”的插件应该可以做到这一点: https://github.com/VincentLeung/nunjucks-includeData

我试图把这个包括进去,但它不起作用。

我做了什么至今:

我添加了一个名为“nunjucks-includedata.js”到哪里吞气任务所在的任务文件夹中的文件。

var nunjucks = require('nunjucks'), 
    includeData = require('nunjucks-includeData'), 
    gulpnunjucks = require('gulp-nunjucks'); 

var templates = 'app/templates'; //Set this as the folder that contains your nunjuck files 

var env = new nunjucks.Environment(new nunjucks.FileSystemLoader(templates)); 
includeData.install(env); 
gulp.task('pages', function() { 
    // Gets .html files. see file layout at bottom 
    return gulp.src([templates + '/*.html', templates + '/**/*.html']) 
     // Renders template with nunjucks and marked 
     .pipe(gulpnunjucks.compile("", {env: env})) 
     // output files in dist folder 
     .pipe(gulp.dest(dist)) 
}); 

但它不起作用。开始的时候,一饮而尽,该标签“includeData”无法识别我得到一个错误。

当然有缺点什么,但我不知道它是什么,我也搜索互联网时,没有发现任何有用的东西。

希望有人已经在使用includeData插件成功地在他的构建过程中,可以告诉我,我有什么在配置改变。

非常感谢您的帮助!

最好的问候, 托马斯

回答

0

首先,你必须检查扩展安装

// test.json 
{"name": "Bill"} 

// your-app.js 
... 
includeData.install(env); 
var res = res.renderString('{% includeData "test.json" %} {{name}}'); 
console.log(res); // Bill 

本扩展不在节点5.x的工作,因为需要解构赋值(见node_modules\nunjucks-includeData\index.js,行78 )。也许,你必须更新节点。