1

how do use a custom tag inside an if tag?

ex:  {% if {%customTag  x y z %} == "Success" %}
        ...

my custom_field_tag:

@register.simple_tag
def customTag(x,y,z):
    r=x+y+z
    if r ==3:
       return "Success"
    else:
       return "Wrong"

2 Answers2

0

Check this two links: 1.django filter and tag documentation

2.For custom template tags and filters: custom template tags and filters

I think you need to see django 'Filters', according to your problem. you will find about every kind of filter needed, if not, it is very easy to write a custom one.

0

You just need to slightly change your logic using Boolean values. For you custom_field_tag:

@register.simple_tag
def customTag(x,y,z):
    r=x+y+z
    if r==3:
        return True 
    return False

Then inside your html template, simply use it this way:

{% customTag 1 0 2 as success_result %}
                        {% if success_result %}
                        <p>it is 3</p>
                        {% endif %}