Template tag called in if statement

I am wondering if there is a way by which you can call the template tag from the instruction if.

I am trying to do the following.

{% for k,v in form.amenities.field.choices %}
    {% if {% check_hidden k %} %}
        {{ v }}
    {% endif %}
{% endfor %}

The tag {% check_hidden k %}returns Trueor Falsefrom the table for the item being viewed. I can confirm that it {% check_hidden k %}returns either True, or False, but I wonder if I can wrap an operator around it if?

The application I'm working with is inherited, so I'm trying to minimize the number of changes that need to be done at the moment. Currently it just displays as {{form.amenities}}, but I added an extra field to the model, which I need to check before displaying the field in the template.

If there is another way to do this, I am open to suggestions.

Thanks in advance.

+3
source share
2 answers

It looks like it check_hiddenwas written as a template tag when you need a filter .

{% if k|check_hidden_filter %}
+6
source

Regardless of what the check_hiddenvalue of choice needs to be fixed in a fundamental way.

If the field selection is dynamic, you need to set the correct set of options in the view function, eliminating the need to do check_hidden in the template in general.

https://stackoverflow.com/search?q=%5Bdjango%5D+dynamic+choices

Gives you many dynamic selection methods. Many of these are executed in the view function, eliminating the need for this kind of if-statement in the template.

0
source

All Articles