Re: Why must {% extends '' %} be first value in template? Inconvenient for ajax versions.

2010-03-28 Thread David Hollander
Goal: produce responses for both ajax and regular requests with a single render_to_response call and no extraneous templates. Solution: 1. dynamic extends. mypage.html: {% extends base %}. base="mybase.html" or "ajaxbase.html" pros: one render_to_response call. cons: Have to create extra dummy

Re: Why must {% extends '' %} be first value in template? Inconvenient for ajax versions.

2010-03-28 Thread Vinicius Mendes
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

Re: Why must {% extends '' %} be first value in template? Inconvenient for ajax versions.

2010-03-28 Thread pjrhar...@gmail.com
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: Foo {% block foo %}{% endblock %} Bar {% block bar %}{% endblock %}

Re: Why must {% extends '' %} be first value in template? Inconvenient for ajax versions.

2010-03-28 Thread Wiiboy
Something I tried once: set the 'extends' template variable in your views (middleware even, maybe) to either an empty string or the path to your template, based on the result of request.is_ajax. I'm not sure though whether Django will throw an error if extends has an empty string. Suggestion:

Re: Why must {% extends '' %} be first value in template? Inconvenient for ajax versions.

2010-03-28 Thread DrBloodmoney
On Sat, Mar 27, 2010 at 9:29 PM, David Hollander 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

Re: Why must {% extends '' %} be first value in template? Inconvenient for ajax versions.

2010-03-27 Thread Sam Lai
Up the top of my head - Create a separate ajax_content.html template for use with AJAX requests (use an if statement in the view to determine which template to load), then include ajax_content.html in the non-AJAX request template to keep things DRY. On 28 March 2010 12:29, David Hollander

Why must {% extends '' %} be first value in template? Inconvenient for ajax versions.

2010-03-27 Thread David Hollander
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.{%