show children nodes depending on selected parent

被刻印的时光 ゝ 提交于 2019-12-03 08:35:55

You need to send down some information about what node you're in, and then it's a simple if statement.

Regarding how to send down the node information universally, there are a couple ways to do this in Django, and none of them are perfect. My preferred method is context processors: http://docs.djangoproject.com/en/1.3/ref/templates/api/#writing-your-own-context-processors

{% recursetree nodes %}
  <li>
      <a href="/category/{{ node.get_absolute_url }}">{{ node.name }}</a>                           
       {% if node.name == category.name %}
         <ul>
            {{ children }}
         </ul>
       {% endif %}
  <li>
{% endrecursetree %}

You can try this:

{% recursetree nodes %}
    #check if the node is a child node
    {% if node.is_child_node %}
        <a href="{{ node.get_absolute_url }}" >{{ node.name }}</a>
    {% endif %}

    #check if a root node is the current category
    {% if node.is_root_node and node.name == category.name %}
        {{ children }}
    {% endif %}

{% endrecursetree %}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!