Evaluating variables in a blocktrans block within templates

81 views
Skip to first unread message

Frankline

unread,
Dec 18, 2014, 7:17:12 AM12/18/14
to django...@googlegroups.com
Hi all,

I recently had a weird problem in my django templates regarding evaluating variables within a blocktrans, but I finally figured it out. I guess I just want to know the reason why it worked, an explanation sort of.

THIS DID NOT WORK
{% blocktrans %}Approve all {{ objects.count }} users{% endblocktrans %}

HOWEVER, THIS WORKED
{% blocktrans with objects.count as objects_count%}Approve all {{ objects_count }} users{% endblocktrans %}

Can someone explain to me the reason behind why the last code statement worked as opposed to the first one?

Thanks.

With Regards,
Frankline

Andreas Kuhne

unread,
Dec 18, 2014, 7:28:21 AM12/18/14
to django...@googlegroups.com
Hi Frankline,

You can only reference variables in the templates directly with the blocktrans tag. See https://docs.djangoproject.com/en/1.7/topics/i18n/translation/#blocktrans-template-tag. So you have to use the "with" statement on blocktrans to access properties of a class.

Regards,

Andréas

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEAUGdX5it8Z3kLGKOspGZj%3DY%3DkstNeLHLvySGtogLXEOO58HQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Frankline

unread,
Dec 18, 2014, 7:39:27 AM12/18/14
to django...@googlegroups.com
Nicely answered.

Thanks Andreas.

Reply all
Reply to author
Forward
0 new messages