Code

Opened 3 years ago

Closed 3 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 aaugustin)

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

Attachments (0)

Change History (2)

comment:1 Changed 3 years ago by aaugustin

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 3 years ago by aaugustin

  • Resolution set to invalid
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.