2

Setup:

  • a tree structure of the models.
  • a representation of that structure in the HTML.

Issue:

How to know at any given recursion level the depth level at which currently I am?

Example:

This is the HTML:

<ul>
    <li>
        0

        <ul>
            <li>1</li>
            <li>1</li>
        </ul>
    </li>

    <li>0</li>
</ul>

0,1 are the children's depth level that I want to get at any given time.

Diosney
  • 10,520
  • 15
  • 66
  • 111

1 Answers1

3

You can use the template variable node.level and it will give you the indentation level.

You can read more about it at:

http://django-mptt.readthedocs.org/en/latest/technical_details.html?highlight=level#level

spac3_monkey
  • 130
  • 1
  • 7
  • Was about to post this, and just to clarify since mptt is only mentioned in a tag here. This applies to django-mptt models, ususally traversed with one of its template tags. – kalhartt Dec 22 '14 at 19:32