AngeloC
AngeloC

Reputation: 3523

how to merge ejs files with json array using gulp-ejs?

gulp-ejs sample code, ejs(json), this applies to all the els files from template folder, my need is, the json is taken from an array depending on the els file name, how to achieve this? thanks

var ejs = require("gulp-ejs");

gulp.src("./templates/*.ejs")
.pipe(ejs({
    msg: "Hello Gulp!"
}))
.pipe(gulp.dest("./dist"));

Upvotes: 1

Views: 790

Answers (1)

soenguy
soenguy

Reputation: 1361

I know nothing about ejs but it seems like, from what I understood, you want to target a specific file, that is :

[...]
    gulp.src("./templates/yourfile.ejs")
[...]

Maybe it's only me but I didn't understand everything, but maybe that you're looking for something like :

var myjson = require(./myjson.json);

gulp.src("./template/"+myjson.filename+".ejs")
.pipe(ejs({
    msg: "Hello Gulp! This is "+myjson.filename
}))
.pipe(gulp.dest("./dist"));

Also, if you're only copy/pasting the example file it looks like you didn't do a lot of research or experiment, but I may be wrong ... If I'm not, try harder before asking.

Upvotes: 2

Related Questions