simon-dt / gulp-twig

Twig plugin for gulp.js, The streaming build system. Looking for maintainer or collaborators. See wiki
https://github.com/zimmen/gulp-twig/wiki/Looking-for-maintainer-or-collaborator(s)
MIT License
62 stars 33 forks source link

Don't output extended templates #20

Closed 1stevengrant closed 8 years ago

1stevengrant commented 8 years ago

Is there a way just to stop that output and just output the templates that extend the base?

simon-dt commented 8 years ago

Not sure what you mean... you would like to output the compiled twig without whatever it extends? Simply not extending those templates isn't an option?

What is the usecase?

1stevengrant commented 8 years ago

For example, I have index.twig that extends layout.twig and when it compiles, I get index.html and layout.html -- layout.html doesn't actually serve any purpose. We're only ever interested in index.html if that makes sense?

simon-dt commented 8 years ago

Ah yes, well, it looks like you are compiling the layout twig file as well. You could solve this in a lot of ways but it comes down to making sure those files aren't included in the gulp.src.

You could create a folder structure where pages and base layouts are on the same level and run gulp-twig on the folder containing the pages.

templates
 |
 |-- layout
 |     |-- base.twig
 |-- pages
 |     |-- index.twig

where index would contain {% extends "../layout/base.twig" %} and gulp.src is something like gulp.src('./templates/pages/*.twig')

You could also prefix files that are ment for extend and include with '_' and exclude them in gulp.src glob like this:

gulp.src('./templates/**/!(_)*.twig')
1stevengrant commented 8 years ago

Gotcha. I normally do _layout.twig but I saw that was compiling too, didn't realise I'd need to manually exclude them.

This worked just nicely in my Gulp config file

twig: {
    src: templates + '/**/[^_]*.twig',
    dest: dest
  },
simon-dt commented 8 years ago

Great, that's kind of like how I do this as well :-)

1stevengrant commented 8 years ago

Also, thank you for this.

Love Twig but everything else for integration was too heavy for simply DRY writing markup.

Now a simple Gulp task and we're golden.

On 1 December 2015 at 17:03, Simon notifications@github.com wrote:

Great, that's kind of like how I do this as well :-)

— Reply to this email directly or view it on GitHub https://github.com/zimmen/gulp-twig/issues/20#issuecomment-161032935.

Steven Grant