On Fri, Jun 5, 2009 at 6:35 PM, Andrew Fong <fongand...@gmail.com> wrote: > > I was hoping someone could explain to me what the exact behavior would > be if the Extends Node in the template was not first. > > Here's my use-case scenario: I need to maintain separate mobile and > desktop templates for my site. I'm finding out that 90% of my > templates would be identical -- the only difference would be which > templates they extended from -- e.g. {% extends 'base.html' %} vs. {% > extends 'm_base.html' %}. > > My views insert a mobile variable into the context if they think the > user-agent is a mobile device. So I want behavior like this: > > {% if mobile_var %} > {% extends 'm_base.html' %} > {% else %} > {% extends 'base.html' %} > {% endif %} > > This won't work because the the extends tag doesn't really understand > the {% if %} tag above it and just throws up when it comes to the {% > else %} tag. So as an alternative, I plan to encapsulate that logic in > a custom extends tag -- e.g. {% mextends mobile_var 'm_base.html' > 'base.html' %} that wraps the existing do_extends function. > > When going over the ExtendNode source code however, I noticed it has > to be first. However, in order to use my custom tag, I need to call {% > load %}, and that call means any ExtendNode created after that can't > be first. I'm tempted to simply disable that, but I'm not really sure > what will happen if I do. Are there any problems with calling a load > tag before an extends? >
I don't know the answer to your question, but here is a suggestion how you might accomplish using a different base template for the mobile version of your site. The extends tag accepts a variable too, so you could just use a context processor to pass the base template into the renderer, something like this (in pseudo-code): def base_template(request): return {'base_template': is_mobile(request) and 'm_base.html' or 'base.html'} And inside your templates, use: {% extends base_template %} Matthias --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---