On Sat, Mar 27, 2010 at 9:29 PM, David Hollander <dhll...@gmail.com> wrote:
> Hello. I am making a restaurant site with some visually candy that
> will load all new subpages via AJAX. And also load pages normally
> without AJAX if javascript is disabled.
>
> Ideally, I want to do:
>
> {% if not ajax %}
>    {% extends 'base.html' %}
> {% endif %}
> {% block content %}Content Here.{% endblock %}
>
> That way I can use the same template for an ajax request as a regular
> request. In a regular request where I pass ajax: False to the
> template, it will extend base.html and add all the background stuff
> such as html header, navigation menu, etc. But if it's ajax, it
> doesn't load any of that unnecessary stuff since that will already be
> present in the page with the ajax request.
> I know I can just return the whole page to an AJAX request and slice
> out the unncessary stuff with jQuery. Or I can create a seperate
> template for the AJAX version. But that would either be very
> inefficient OR violate the DRY principle.
>
> What is the best idiom to handle this situation?
>
> Thank you for your time.
> -David
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

I do it the other way with AJAX in mind, mostly because I want my code
to fail gracefully:

Make your non-javascript template with the fragments you will
otherwise return as html included in the template:

{% include "ajax_fragment.html" %}

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to