User User - 1 year ago 101
Python Question

Combine tags with filters


{% firstof m.caption m.altcaption|slice:":37" %}

I want to choose the first of those 2 variables, then slide to 37 characters. Any ideas?

Answer Source

In Django 1.9+ you can assign the result of the firstof tag to a variable.

{% firstof m.caption m.altcaption as caption %}
{{ caption|slice:":37"}} 

In earlier versions you could filter both arguments

{% firstof m.caption|slice:":37" m.altcaption|slice:":37" %} 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download