node-swig / swig-templates

Take a swig of the best template engine for JavaScript.
http://node-swig.github.io/swig-templates/
MIT License
209 stars 29 forks source link

make 'ignore missing' an option on Swig Options object #44

Open steevhise opened 7 years ago

steevhise commented 7 years ago

It seems reasonable to want an "ignore missing" setting that is more general, in other words that can apply everywhere and not need to specify it for each specific use of the "include" tag. Perhaps it should even apply to entire templates that are missing. Why not make it an option to pass to the Swig Options object?

cdaringe commented 7 years ago

similar to #45, i somewhat think this is a preprocessing concern. im not super against it, but im having a little bit of skepticism seeing it as swig's responsibility. maybe you can paint a use case where it really helps/would-help to sell it?

steevhise commented 7 years ago

I admit that applying to an entire template is perhaps a stretch. But if there's already an "ignore missing" option for the include tag, it seems like having a global setting for all include tags wouldn't be much of an additional performance hit. ( One use case is having a set of template partials that I want to optionally bring in from another package. I'd want the templates that include them to not fail if that package isn't present, without having to go in and add "ignore missing" to every include tag. )

steevhise commented 7 years ago

I've written a custom template loader that does this, as well as #45. So no worries if y'all don't want to implement these.

steevhise commented 7 years ago

Here's a gist of our custom template loader that basically solves both this and #45: https://gist.github.com/steevhise/2ddac162d43c3a6112d3e983c73b4e32