Skip to content
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

Pipe modified templates by passing file.contents into twigOpts.data #30

Closed
signal-intrusion opened this issue Aug 16, 2016 · 1 comment

Comments

@signal-intrusion
Copy link

signal-intrusion commented Aug 16, 2016

This gulp task does not allow us to pipe in files where we have changed the template in a previous gulp task. For example, we have templates with front matter that we remove (check out the example in the gulp-data repo), but the front matter is still rendered.

Passing the file contents as the data property to twigOpts. twig.js will use the string in file.data when you call Twig.twig(twigOpts). Check out the twig.js source where it renders a template from params.data: https://github.com/twigjs/twig.js/blob/master/src/twig.exports.js#L41-L48

This would allow gulp tasks to, in effect, change templates before rendering them. It would also speed up rendering because it will use buffered data, avoiding an expensive call to Twig.loadRemoteContent() fetching templates from the filesystem.

      var Twig = require('twig'),
            twig = Twig.twig,
            twigOpts = {
                path: file.path,
                async: false
            },
            template;

        if (!!useFileContents) {
            twigOpts.data = String(file.contents);
        }
mgburns added a commit to mgburns/gulp-twig that referenced this issue Nov 9, 2016
Allows modification of template contents in Gulp stream, avoids file system access. Fixes simon-dt#30.
@bezoerb
Copy link
Collaborator

bezoerb commented Jan 15, 2018

@bezoerb bezoerb closed this as completed Jan 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants