views:

94

answers:

3

How do I do this:

{% if thestring %}

    {% if thestring.find("1") >= 0 %}

    {% endif %}

{% endif %}

I am assuming I need to build a template filter? Will that work?

+3  A: 

It would. But use the in operator instead of the find() method.

Example:

{% if thestring|contains:"1" %}
Ignacio Vazquez-Abrams
+1  A: 

I believe you'll find that the Django template system isn't designed to have complex logic in it. This type of processing should happen in your view, then be passed to the template.

Jack M.
+2  A: 

You don't need to build a custom filter, though one would work -- the alternative of coding

{% if thestring %}

    {% if "1" in thestring %}

    {% endif %}

{% endif %}

would also go just fine.

Alex Martelli
Relational and containment operators in `{% if %}` are only in the development version.
Ignacio Vazquez-Abrams
True -- it's only scheduled for release (as 1.2) in 3 weeks.
Alex Martelli