Question

how can i create an outline like this code will produce

<ol type="1">
    <li>Fruit
        <ol type="a">
            <li>Apples</li>
            <li>Bananas</li>
            <li>Oranges</li>
        </ol>
    </li>
    <li>Vegetables
        <ol type="a">
            <li>Carrots</li>
            <li>Lettuce</li>
            <li>Cucumbers</li>
        </ol>
    </li>
</ol>

but in jinja2... i tried this, and it just doesn't want to work

{% for project in P %}
<ol>
<li> Project: {{ project.name }}

    {% for pgoal in project.goals.all() %}

    <ol type="A">
    {% if loop.last %}</ol></li>{% endif %}
    <li>Goal: {{ pgoal.goal }}</li>

       {% for pstrat in pgoal.strategies.all() %}
       {% if loop.last %}</ol></li>{% endif %}
            <ol type="a">
       <li> Strategy: {{ pstrat.strategy }}</li>

        {% for ptask in pstrat.tasks.all() %}
        <li>Task: {{ ptask.task }} complete? {{ptask.complete}}</li>
       <ol type="1">
       {% if loop.last %}</ol></li>{% endif %}
       {% endfor %}
      {% endfor %}
    {% endfor %}
 {% endfor %}
Was it helpful?

Solution

Something like this would show a nested <ol> structure for your nested objects:

<ol>
  {% for project in P %}
  <li> Project: {{ project.name }}

    <ol type="A">
      {% for pgoal in project.goals.all() %}
      <li>Goal: {{ pgoal.goal }}

        <ol type="a">
          {% for pstrat in pgoal.strategies.all() %}
          <li> Strategy: {{ pstrat.strategy }}

            <ol type="1">
              {% for ptask in pstrat.tasks.all() %}
              <li>Task: {{ ptask.task }} complete? {{ptask.complete}}</li>
              {% endfor %}
            </ol>

           </li>
           {% endfor %}
         </ol>

       </li>
       {% endfor %}

    </ol>

  </li>
  {% endfor %}
</ol>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top