1

My nav pills appears in a single row. But once I add django template tags to it, the pills stacks on top of each another.

How do I fix it so that the pills appear all in one row?

Without django tags

<ul class="nav nav-pills">
  <li role="presentation" class="active"><a href="#">Home</a></li>
  <li role="presentation"><a href="#">Profile</a></li>
  <li role="presentation"><a href="#">Messages</a></li>
</ul>

With django tags

{% for menu in menus %}
<ul class="nav nav-pills">
    {% if menu.mealtype == 'Breakfast' %}
        <li role="presentation" class="active"><a href="#">Home</a></li>
    {% endif %}
    {% if menu.mealtype == 'Lunch' %}
        <li role="presentation"><a href="#">Profile</a></li>
    {% endif %}
</ul>
{% endfor %}

1 Answer 1

1

Your problem is that your for loop {% for menu in menus %} repeats the <ul> tag as well. You are making a separate list per entry.

Try moving your for loop inside the <ul> tags.

<ul class="nav nav-pills">
{% for menu in menus %}
    {% if menu.mealtype == 'Breakfast' %}
        <li role="presentation" class="active"><a href="#">Home</a></li>
    {% endif %}
    {% if menu.mealtype == 'Lunch' %}
        <li role="presentation"><a href="#">Profile</a></li>
    {% endif %}
{% endfor %}
</ul>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the quick answer. Works perfectly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.