Ah. Ok. I think I understand. It's good to look at it from a distance.
How do traditional template systems work? You specify some chain:
A → B → C → D
Something uses D. Then the system goes all the way up to A and starts
processing. Then it hits some template thing (eg. ${self.title()} in
Mako notation) and goes down again to find the lowest definition of
title in the chain.
Compare this to the functional approach above:
We start processing at D (which is like C and B (maybe a function
containing) a snippet, A would be a template) and pass on the result
as input to C. When we reach A, would are finished. Every level has
only to know itself and maybe the parameters required for the next
step. Here a short example.
(deftemplate A "base.html"
[kontent title sidebar]
[:title] (content title)
[:sidebar] (substitute sidebar)
[:div#content] (content kontent))
(defn b
[content title]
(A content title (make-b-sidebar)))
(defn x
[content title]
(let [x-content (snippet .....)]
(A (x-content content) title (make-x-sidebar))))
Looking at this, makes it seem so simple. And the inheritance is done
implicitly by the function call chain. I will definitively give this a
try.
I think my main mistake, was think to much about the HTML templates
themselves. This is maybe a relic of the traditional systems, where
logic is put into the template. With enlive the template is really
only the skeleton with the logic put into the clojure code.
Sincerely
Meikel
Ah. Ok. I think I understand. It's good to look at it from a distance. How do traditional template systems work? You specify some chain:
A → B → C → D
Something uses D. Then the system goes all the way up to A and starts processing. Then it hits some template thing (eg. ${self.title()} in Mako notation) and goes down again to find the lowest definition of title in the chain.
Am 11.10.2009 um 11:24 schrieb Christophe Grand:
> It's very much like OOP: D inherits render() from A (via B and C)
> and calls title() which is overridden in D.
> I think it's worth trying to use functional templates and not
> implementing an object system on top of Enlive.
This is exactly what I will do! I will definitively try the functional
approach!
I will post my results to the list. :) (if the move to the new
apartment allows early results.. sigh)
Sincerely
Meikel