I implemented two solutions for this problem. The first one is the solution
already said here: create a template context processor that inserts a
variable in context with the name of the base template ("base.html" for
normal requests and "base_ajax.html" for ajax requests).
The second one is a bit more complicated. I created a new template tag based
in the {% extends %} that ships with django. The template tag receives the
name of the base template and substitutes ".html" with ".xhr" if the request
is an ajax request. For example: if the template name is "base.html" and the
request is normal, then it will extend the "base.html". But if the request
is ajax, then it will extend the "base.xhr".
I'm thinkin about creating a post in my blog talking about this template
tag. What do you think?
______________________
VinÃcius Mendes
Solucione Sistemas
http://solucione.info/
http://meiocodigo.com/
On Sun, Mar 28, 2010 at 9:10 PM, [email protected] <[email protected]>wrote:
> Ideally, I want to do:
> >
> > {% if not ajax %}
> > {% extends 'base.html' %}
> > {% endif %}
> > {% block content %}Content Here.{% endblock %}
>
> Extends can't be optional. Consider the following:
>
> base_template.html:
> <h1>Foo</h2>
> {% block foo %}{% endblock %}
> <h1>Bar</h2>
> {% block bar %}{% endblock %}
>
> other_template.html:
> {% extends "base_template.html" %}
> {% block foo %}Foo{% endblock %}
> {% block bar %}Bar{% endblock %}
>
> Now where do "Foo" and "Bar" appear if you don't have the extends?
>
> Either use an includes, or pass the name of your base template as a
> variable so you can extend "base_template.html" or
> "ajax_base_template.html" which would leave out all the extras.
>
> Peter
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<django-users%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.