Templating Pitfalls?

2006-02-15 Thread [EMAIL PROTECTED]

I was wondering, in response to more complex templating setups. If as a
user, you wanted to subclass a parent template, but the parent template
needs to dynamically generate content given a data source. An example
could be a calendar of events that you want displayed on every page.
The child page should not have to get those events and pass it to the
renderer. Is there some convention that Django follows, and if not,
what seems to be the most practical way for people who have dealt with
this?



Re: Templating Pitfalls?

2006-02-15 Thread Julio Nobrega

  With "child page should not have to get those events" you mean not
passing the events list as a variable to render_to_response() on each
view?

  Well, I am using template tags. These are
objects/functions/variables available globally on your templates. It's
actually what I use to generate items for a navigation menu, which is
data pulled from a database and displayed on every page:

{% load templatetag_file %}
{% function_from_templatetag %}
{% for item in return_from_function_above %}
{{ item }}
{% endfor %}

  The template tag can also return HTML code, something you might want
to consider giving the requirement (a calendar).

On 2/15/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> I was wondering, in response to more complex templating setups. If as a
> user, you wanted to subclass a parent template, but the parent template
> needs to dynamically generate content given a data source. An example
> could be a calendar of events that you want displayed on every page.
> The child page should not have to get those events and pass it to the
> renderer. Is there some convention that Django follows, and if not,
> what seems to be the most practical way for people who have dealt with
> this?
>
>


--
Julio Nobrega - http://www.inerciasensorial.com.br


Re: Templating Pitfalls?

2006-02-15 Thread Maniac


[EMAIL PROTECTED] wrote:


I was wondering, in response to more complex templating setups. If as a
user, you wanted to subclass a parent template, but the parent template
needs to dynamically generate content given a data source. An example
could be a calendar of events that you want displayed on every page.
The child page should not have to get those events and pass it to the
renderer. Is there some convention that Django follows, and if not,
what seems to be the most practical way for people who have dealt with
this?
 

Apart of template tags that Julio suggested you can use 'context 
processors'. Those are custom functions executed for each response that 
add some data needed in all pages. The most obvious example is passing 
reference to currently logged in user for each page.


The docs for context processors are here: 
http://www.djangoproject.com/documentation/templates_python/#subclassing-context-djangocontext