[Haskell-cafe] Templates as typeclasses?
mwm at mired.org
Fri May 9 07:34:52 UTC 2014
On Fri, May 9, 2014 at 2:11 AM, Tobias Florek <haskell at ibotty.net> wrote:
> The objects generated by the templates don't do much of
>> anything to let the application author leverage the type system, which
>> is what makes Cheetah stand out from other web template systems.
> can you elaborate on that point? i would really like to see an example on
> what you mean.
> for another datapoint, have a look at hastache's use of generics
I mentioned that briefly in the original message: A Cheetah template is a
Python class. It can inherit from Python classes, and Python classes can
inherit from it.
A standard usage is to have a page template that sets up headers and
footers, and make your pages are all children of that class. While
header/footer support is a stock feature of any modern templating system,
Cheetah does it by leveraging it's integration into the Python class system
instead of providing a specific mechanism for it.
If you need something to happen on the server when the page renders - that
doesn't leave any traces in the output - you can subclass the template with
a standard Python class and provide that functionality. You then use the
Python subclass just like a regular template. Again, the behavior isn't
special, but doing it takes no special machinery, just leveraging Cheetah
templates being classes.
You can find simple examples of this in the Cheetah docs:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe