2017-08-25 53 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 )。也許,你必須更新節點。