When using twig templates gulp-inject transform adds in asset() function that is from Symphony and not Twig.
silktown-software opened this issue · 1 comments
I am using gulp-inject to generate me two templates one for my CSS and JS that is built separate by gulp.
If I name the template files *.html
it will do the replacement of the path correctly. If I name the files *.twig
it will add the file path in with the mustache variables and add an asset()
function.
e.g.
<link rel="stylesheet" href="{{ asset("/static/styles/styles.css") }}" />
If you look at the twig reference the asset()
isn't defined in twig itself.
It appears to be part of symphony framework.
Looking at:
`/node_modules/gulp-inject/src/transform/index.js
lines: 148-203
transform.twig.css = function (filepath) {
return '<link rel="stylesheet" href="{{ asset("' + filepath + '") }}"' + end();
};
transform.twig.js = function (filepath) {
return '<script src="{{ asset("' + filepath + '") }}"></script>';
};
This behaviour appears to be incorrect as this isn't part of twig, it appears as part of symphony. I am using Twig without Symphony.
For reference:
My create templates task function:
const createTemplates = () => {
const sources = src([
'../webapp/src/static/**/*.js',
'../webapp/src/static/**/*.css'
]);
return src('./templates/*.twig')
.pipe(inject(sources, {
ignorePath: ['..', 'webapp', 'src'],
removeTags: true,
selfClosingTag: true,
}))
.pipe(dest('../webapp/src/templates/shared/static'));
}
My css.twig
<!-- inject:css -->
<!-- endinject -->
My js.twig
<!-- inject:js -->
<!-- endinejct
Closing this issue as I no longer use gulp