zephyr19
zephyr19

Reputation: 23

Django Wagtail template - if statement not working

Hi hopefully this is a simple fix. I'm still fairly new to Django/Wagtail and would appreciate any help. My goal is to better format my form fields by filtering with the field.label_tag value.

I know for a fact the value of field.label_tag is as expected, but still no luck after confirming the output in the template and trying a few variations on the if statement.

      {% for field in form.visible_fields %}
        <div class="control-group">
          <div class="form-group floating-label-form-group controls">
            <label>{{ field.label_tag }}</label>
            {% if field.label_tag|stringformat:"s" == "Email Address" %}
              <strong>field.label_tag</strong> 
            {% endif %}
            {% if field.label_tag|stringformat:"s" == "Message" %}
              {% render_field field class+="form-control" placeholder+="Message" id+="message" %}
            {% endif %}
            <p class="help-block text-danger"></p>  
          </div>
        </div>
      {% endfor %}

Upvotes: 2

Views: 648

Answers (1)

MohitC
MohitC

Reputation: 4791

If you want to string match with label of field, you can do

if field.label|stringformat:"s" == "Email Address"

Upvotes: 1

Related Questions