User User - 6 months ago 59
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?


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" %}