On 12 déc, 21:25, Alex Rades <alera...@gmail.com> wrote:
> Hi,
>
> I have a master template which defines two blocks:
>
> {% block account %}{% endblock %}
> {% block content %}{% endblock %}
>
> I have a templatetag which tells me the time of the last image upload
> (it's a photo sharing site).
> This templatetag hits the database, and I don't want to call it
> multiple times in the same page.
>
> The problem is that if I do:
>
> {% get_last_upload as last_upload %}
>
> I cannot access the variable 'last_upload' from the two blocks.

When extending a template, anything outside blocks in the extending
template is ignored (except for {% load ... %} tags).

> I have
> to call the the templatetag twice, one in each block.
>
> Is there a way to share variables between blocks?

Yes : use the context. Either in the somewhat hackish way explained by
pjrharley, or within your views, or - might be the better solution in
your case - using a context processor.

My 2 cents.

PS : I still think allowing "context updating" nodes outside blocks in
extending templates might be a good thing . FWIW I had a working
(albeit very Q&D) implementation, but got too negative feedbacks on
the idea on django-dev to bother working on a cleaner implementation
and submiting a patch.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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