Thursday, June 26, 2014

Combining use of template tag + filter in same expression

I have a template in which I'm trying to achieve the use of the
'firstof' tag to display whichever of two variables is present, and
the resulting variable filtered through 'truncatewords'. Is there a
way this can be accomplished?

Have tried the following:

{% first of result.meta.summary|truncatewords:12
result.description|truncatewords:12 %}

It doesn't work as I thought it might, instead rendering 'None' in the template.

This construct seems to work as expected if only the last variable is
applied the filter:

{% firstof result.meta.summary result.description|truncatewords:2 %}

Can this be made to work? Or is the combination of firstof and a
filter on more than the last variable unsupported?

Python 2.7.7
Django 1.6.5

--
Darren Spruell
phatbuckett@gmail.com

--
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/CAKVSOJUCLm1b4UBny31Z8MZxMUTxou0GR2WW5HsYn_vjcMvt5w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment