On Wed, Jun 24, 2009 at 11:19 AM, buttman <cp368...@ohio.edu> wrote:

> Whats wrong with:
>
> {% with something as x %}
>
> {% block foo1 %}
> {{x}}
> {% endblock %}
>
> {% block foo2 %}
> {{x}}
> {% endblock%}
>
> {% block foo3 %}
> {{x}}
> {% endblock%}
>
> {% block foo4 %}
> {{x}}
> {% endblock %}
>
> {% block foo5 %}
> {{x}}
> {% endblock %}
>
> {% endwith %}
>
> just simply being a shortcut for:
>
>
>
> {% block foo1 %}}
> {% with something as x %}
> {{x}}
> {% endwith %}
> {% endblock %}
>
> {% block foo2 %}
> {% with something as x %}
> {{x}}
> {% endwith %}
> {%endblock%}
>
> {% block foo3 %}}
> {% with something as x %}
> {{x}}
> {% endwith %}
> {%endblock%}
>
> {% block foo4 %}}
> {% with something as x %}
> {{x}}
> {% endwith %}
> {%endblock%}
>
> {% block foo5 %}
> {% with something as x %}
> {{x}}
> {% endwith %}
> {% endblock%}
>
> Seem like it just makes things easier to read and maintain. If the
> second example works perfectly fine, then why shouldn't the first?
>

There's nothing wrong with your first example as written, that's perfectly
legal.  There's no need to repeat the {% with %} inside each block.  But
note you haven' t made your example a child template -- it doesn't start
with {% extends %} -- and that's the key.  If this were a child template,
you'd have to do it the 2nd way, or place the {% with %}/{% endwith %} in
the parent template enclosing all the blocks where you wanted it to have an
effect.  That's because content in a child template that is outside of any
named {% block %} that has been defined in a parent template has no place to
go in the ultimately rendered template, so it may as well not be there.  I
don't know how to restate this to try to make it any clearer than the ways
I've already tried to explain it.

The title of this thread is not really accurate.  {% with %} can span
blocks, it just can't do so in a child template since NOTHING outside of {%
block %}s (and {% extends %}) in a child template has any effect.  If you
know the order of the block placement in the parent template I suppose it
might work to put the {% with %} within the first block and the {% endwith
%} at the end of of the last block, but that's quite ugly. It does lead me
to think of another way, though.  You could define "start_withs" and
"end_withs" blocks and properly place them in the parent tempalte, then
define them with overriding content in the child templates, I suppose, if
you really need to do this kind of thing.

Karen

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to