Opened 13 years ago

Closed 13 years ago

#16348 closed Uncategorized (invalid)

{%with%} variable values not available in {%include%}'ed templates

Reported by: leim@… Owned by: nobody
Component: Core (Other) Version: 1.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Aymeric Augustin)

I have the following scenario. (Django version: 1.2.3).

Template A {% include %}s Template B with a {% with %} block:

{% with 'aaa' as a %}
 {% include "template_b' %}
{% endwith %}

Any direct references to 'a' in template_b works just fine, including working with filters. However, a does not appear to be included in the Request object's GET or POST. This means that, for example, any custom context processors attached to Template A does not see the variable a.

Is this expected behaviour? or I am missing some thing here?

Thanks,
Lei

Change History (2)

comment:1 by Aymeric Augustin, 13 years ago

Description: modified (diff)

Fixed formatting (please check the preview before submitting a bug).

comment:2 by Aymeric Augustin, 13 years ago

Resolution: invalid
Status: newclosed

You don't appear to be describing a bug in Django — or if you are, I really can't figure out what it is. For general support with Django, you should join #django on FreeNode or write to the django-users mailing list.


Any direct references to 'a' in template_b works just fine, including working with filters.

OK.

However, a does not appear to be included in the Request object's GET or POST.

What Request object? How is this related to the previous and next sentences?

This means that, for example, any custom context processors attached to Template A does not see the variable a.

Well, context processors process the context before the template is rendered. Obviously, a doesn't exist at this time. The template in general, and with tags in particular, can't be processed before all the context processors have run. For instance, a context processor can add spam to the context, and you can use {% with spam.eggs as omelette %} in the template.

Note: See TracTickets for help on using tickets.
Back to Top