-
Notifications
You must be signed in to change notification settings - Fork 22
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
Templates in templates #26
Templates in templates #26
Conversation
@kylepaulsen Interesting solution. This would add template inheritance-like functionality in libraries that don't support it out of the box, like handlebars. For the ones that do, though, for eg. swig (that's what the test case is written in), jade, and few others, you can already do this like so:
|
@mayo, Ah! I never tried using the inheritance features of jade or swig with the metalsmith-templates plugin - I was just really confused about how that would work. But yeah, I was using handlebars when I was looking for this functionality. Thanks for the example code. I may switch to swig or jade. |
Although one thing this does that I'm not sure can be done currently, is that it renders content like the "inPlace" option does in the content file and then follows and renders the templates. |
@kylepaulsen, if you want to be able to extend templates with Handlebars, you could also use the handlebars-layouts library. It already works for extending files in the See issue #22 for further discussion (hope I'm not misunderstanding your PR btw.) |
I think maybe many use cases for this are solved by the master template proposed in #21? |
@krawaller The master template would allow for one extra level of nesting. But extending templates would allow for unlimited nesting. So I'd say that the master template pr is a little too specific compared to extending templates. The way I see it this pr actually adds two types of functionality:
I think 1. does not have to be solved from within metalsmith-templates. The functionality is already there with swig, jade, etc. or can be added with custom helpers (with handlebars-layouts for example). No need to complicate metalsmith-templates with something that already exists outside of it, in my opinion. Now 2. is actually not possible without changing metalsmith-templates (or adding an extra step that just processes the content files, with consolidate.js or something, which isn't DRY at all). It would make sense to me to ditch 1. and focus on 2., that's where the real problem lies in my opinion (fixed with an option like |
After using a few other static site generators, this is something that I was expecting would work out of the box. I don't think that the ability to have this work with engines like Handlebars is the only advantage here. I've switched to Swig for the project I'm working on to get some of the functionality that's provided here, but being able to define new variables within the front-matter of templates would allow solutions that (as far as I can tell) aren't possible by just using Swig as it doesn't have something similar to a Coupled with the ability to support recursive template building with any template engine, I think this is a must-have feature for Obviously, @kylepaulsen is not alone in wanting this to happen. #27 and #21 are requesting similar functionality. This PR seems to me like it's heading down the right track & addresses the issues from both of those PRs. It feels very natural & is very similar to the way that Jekyll handles templates. It's the way that I assumed things would work. Thanks for all the hard work on this, by the way @ianstormtaylor and @kylepaulsen. |
I agree with what's being said here, and hope this PR will get some love. |
@joakim Something like this can also be done with handlebars-layouts, see here for an example using metalsmith-templates. Works very well. |
Hey thanks for this sorry for the delay. Now that https://github.com/superwolff has split out this plugin into two separate plugins—layouts and in-place—I'm going to deprecate the Added a deprecation notice to the readme. (I think the idea of recursive layouts is genius btw. Very elegant.) |
Add recursiveRender option to allow templates to have templates.
I know this is kind of a crazy change, but I'd thought I'd share it with you in case you'd allow it. I feel like this feature really gives me a lot of power for very little set up (see the test case). Feel free to change whatever or ask me to change things.
Thanks anyway for the code.