Make wrapping in a single layout template easier #3

Open
isaacs opened this Issue Jul 7, 2012 · 3 comments

Comments

Projects
None yet
2 participants
Owner

isaacs commented Jul 7, 2012

Right now, I'm doing this everywhere:

res.template('layout.ejs', { content: 'foo.ejs' })

and that's stupid.

It'd be better if I could just define the wrapper in one place, and then pass it in a 'main' local with the "real" template name. Like this

var template = res.template = Templar(req, res, {wrapper: 'layout.ejs'})
res.template('foo.ejs', {other stuff})
<% // layout.ejs %>
<html><stuff>
<%- main()  // == include('foo.ejs', locals) %>
</stuff></html>

balupton commented Aug 2, 2012

Have you thought about using DocPad? It already supports layouts, pre-processors, partials, includes as well as things like plugins, meta-data, static site generation, etc.

Owner

isaacs commented Aug 2, 2012

Templar is designed to support the needs of isaacs/npm-www . The design philosophy of that site is sort of the opposite of everything DocPad is.

balupton commented Aug 3, 2012

Thanks for that and no worries! It has left me somewhat confused however :( as it seems the design philosophy's stance on "no framework - instead lots of small simple modules" is more or less building a framework in on itself - just one of interchangeable parts that aren't guaranteed to play nice together. Arguably DocPad provides the same goal of interchangeable parts but due to a consistent plugin API that helps to ensure they all play nice together.

The other design philosophies appear to align completely with DocPad, fast, in-memory, stylus support, compatible with search engines - with the other design philosophies being more centered around application development rather than template rendering and writing, so not applicable in this case.

The biggest difference I can see is that DocPad is primarily used with a bottom-up development style - templates come first, then server logic - whereas templar goes the top-down style - server logic comes first, then templates. However DocPad can also be used top-down in more or less the same way as templar via its API, so that kind of evens that difference out... in fact, it would be rather easy to plug the exact templar API directly on top of DocPad.

Give all this, it seems from my perspective that with enough feature requests (for instance this one about in-template layout support) templar could eventually fall into the same boat as DocPad (at least feature-set wise). So I'm real curious to hear your contrast between the two, as I'm failing to spot the differences on this one.

Also sincerely thanks for the opinion btw, really appreciate it. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment