--- On Thu, 2/12/09, Chris Czub <[email protected]> wrote:
> From: Chris Czub <[email protected]>
> Subject: [Templates] Django-style "extends" directive?
> To: [email protected]
> Date: Thursday, February 12, 2009, 7:17 AM
> Hello, I've been using Template Toolkit for about four
> years now and have
> recently been working more and more in the Python+Django
> framework on a new
> project I've been constructing.
> The templating language in Django has given me some
> inspiration for what
> would, in my opinion, make the TT templates we use in our
> business much
> cleaner and easier to maintain.
>
> Django has the concept of "extend"ing another
> template. This is somewhat
> similar at first glance to the "wrapper"
> directive in TT, however the Django
> "extends" directive allows you to override
> specific contents of a base
> template.
>
> That is, for the general and simple example, you would
> define a base
> template with the layout of your site and some default
> contents.
>
> Django template code:
>
> index.html:
> <div id="head">
> {% block head %}
> <h1>CatConnoisseur.com</h1>
> {% endblock %}
> </div>
> <div id="content">
> {% block content %}
> <p>Welcome to the front page of my site!</p>
> {% endblock %}
> </div>
>
> If you were to load the index.html template through the
> Django template
> processor, it would show you a page that had a headline,
> "CatConnoisseur.com" and a paragraph text,
> "Welcome to the front page of my
> site!"
>
> Then you would make another template:
>
> photos.html:
> {% extends "index.html" %}
>
> {% block content %}
> <p>Here are some cats!</p>
> <ul>
> <li><img
> src="/img/cat1.jpg"/></li>
> </ul>
> {% endblock %}
>
> The "extends" block means, roughly, to take
> index.html and replace any
> blocks inside of it with the ones defined in the current
> file, photos.html.
>
> So when you load this page through the Django template
> processor you'd see
> the default "CatConnoisseur.com" header and then
> the contents of the main
> content div would be replaced by the "Here are some
> cats!" text and the
> photo.
>
> Has any thought been put into putting something similar
> into Template
> Toolkit? Is there strong opposition for any reason? I am
> considering making
> a local branch and writing this functionality in for my own
> purposes. Is
> anybody else interested?
I've also been working on something similar, but as also interested in support
the concept of template roles, which is similar in concept to Moose::Role, in
that it allows you to aggregate behaviors in a way I personal find more natural
now that I've been doing Moose for a while.
I was looking at Template::Alloy as a place to possible work on this, since
people seem to be using that to experiement with new syntaxes.
john
> _______________________________________________
> templates mailing list
> [email protected]
> http://mail.template-toolkit.org/mailman/listinfo/templates
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates