Hi Mae,

On Mon, 2006-08-28 at 14:53 +0000, Mae wrote:
> I want included-including templates to be able to act independently
> from each other.  I want the including template to not have to know
> anything about the particulars of the template it's including.
> 
> I want to be able to write {%include magic_template%} and
> magic_template would be a url that would get mapped to its own view
> function, which would do complex database access operations, open
> sockets, do business logic, whatever, before returning
> magic_template.html.
> 
> I have dozens of pages.  All of those pages are different from each
> other, but they all have one thing in common -- they include
> ticker.html.  Now this ticker.html requires certain variables to be
> pre-populated.  Right now, I have to manually attach every single one
> of those variables to every single view function for every single page.
>  If I need to add another variable, I'll have to paste its name into
> dozens of "render_to_response" statements.  This is a maintenance mess.
>  And every single page is obliged to know that it's including
> ticker.html, because it has to pass variables to it.  That's an
> architectural mess.

This can't be done with the {% include %} tag, but it is the ideal
example of when a custom template tag is useful. After writing the tag,
including the tag as 

        {% ticker_data %}

wherever you needed it in your template (plus a "{% load ... %}" at the
top) is all you would need to do.

If your ticker data is best formatted via a small template fragment,
look at the inclusion_tag() shortcut for template tags ([1]). Otherwise,
you probably just need a simple_tag() template tag -- see [2] -- since
you are just returning a string from minimal (in fact, no) input
parameters.

[1]
http://www.djangoproject.com/documentation/templates_python/#inclusion-tags

[2]
http://www.djangoproject.com/documentation/templates_python/#shortcut-for-simple-tags

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to