-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data object overwritten #21
Comments
Did you get around this by any chance? I filed #22 which I think might be somehow related. |
I just added |
I'll have to look into this. Are you seeing the initial data object being mutaded by the twig templates themself? That should not happen ... Are you excluding the layout.twig from the src? |
I'm experiencing the same issue, and I think I have a workaround (until the bug is fixed). If you use gulp-foreach to compile each template in a separate process, it seems to fix the problem of variables "leaking" between templates. However, note that if you are also providing the 'data' option when you call gulp-twig, you must also copy/clone the object that you provide (otherwise the data continues to "leak" between templates, even if you're compiling them separately via gulp-foreach). For example, before I had this in my gulpfile:
...so I changed it to this (note that I'm using gulp-foreach and cloning the data object):
I'm honestly not sure how/why exactly this works, but so far it seems to do the trick for me. |
Any progress on this? I'm running into the same issue. |
You can use var gulp = require('gulp'),
data = require('gulp-data'),
foreach = require('gulp-foreach'),
twig = require('gulp-twig');
// with data as a variable
var myData = {
foo: 'bar',
baz: 'qux'
}
gulp.task('twigWithExternalData', function() {
return gulp.src('./src/**/*.twig')
.pipe(data(myData))
.pipe(foreach(function(stream, file) {
return stream
.pipe(twig())
}))
.pipe(gulp.dest('./dest/'));
});
// with data included directly
gulp.task('twigWithInternalData', function() {
return gulp.src('./src/**/*.twig')
.pipe(data({
foo: 'bar',
baz: 'qux'
}))
.pipe(foreach(function(stream, file) {
return stream
.pipe(twig())
}))
.pipe(gulp.dest('./dest/'));
}); |
I'm using gulp-twig as follows (simplified) :
And y have 3 templates :
The output of
challenge.twig
is correct, buthome.twig
outputsChallenge !
I tried debugging using this :
And it shows that the
data
object is modified with the variables of my template and then shared between the twig files :The text was updated successfully, but these errors were encountered: