isaacs / templar

A lightweight template thing for node http servers
ISC License
36 stars 9 forks source link

Make wrapping in a single layout template easier #3

Open isaacs opened 12 years ago

isaacs commented 12 years ago

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 12 years ago

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.

isaacs commented 12 years ago

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 12 years ago

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. :)