Thursday, December 18, 2014

Re: Evaluating variables in a blocktrans block within templates

Nicely answered.

Thanks Andreas.

On Thu, Dec 18, 2014 at 3:27 PM, Andreas Kuhne <andreas.kuhne@suitopia.com> wrote:
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

2014-12-18 13:16 GMT+01:00 Frankline <fraogongi@gmail.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

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/CALXYUbkfrmAUShH_VSbw8s0ih-8V21zWQ3FfwQCHVcaDum91qg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/CAEAUGdVpUOHS%2Br2EuH6BYTawdPvhPuLvcGe7xxc5P-p7rHZe5A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment