Looping through the child node

286 views
Skip to first unread message

Swaroop Shankar

unread,
Dec 24, 2011, 3:39:10 PM12/24/11
to django-mptt-dev
Hi, I was trying to implement the django-mptt in my project. i was
following the tutorial in http://django-mptt.github.com/django-mptt/tutorial.html
and it worked fine. The problem for me is that in the template, before
i display the child nodes i need to do apply some logic for each of
those nodes. Since {{ children }} is displayed in formatted html
block i am not able to do those logical checks on the data. So how can
i loop through the child node just like the parent node in a template?
Thanks

Craig de Stigter

unread,
Dec 24, 2011, 6:54:58 PM12/24/11
to django-...@googlegroups.com
Hi

The {{ children }} block renders the whole {% recursetree %} template fragment for the child nodes. So you just need to put the logic in the template fragment.

The example in http://django-mptt.github.com/django-mptt/templates.html explains it pretty well I think.

Craig de Stigter

Swaroop Shankar

unread,
Dec 24, 2011, 11:40:53 PM12/24/11
to django-mptt-dev
That's pretty cool, I didnt knew the same logic of parent will be
applied for child nodes too. Thanks a lot for the information.

On Dec 25, 4:54 am, Craig de Stigter <craig...@gmail.com> wrote:
> Hi
>
> The {{ children }} block renders the whole {% recursetree %} template
> fragment for the child nodes. So you just need to put the logic in the
> template fragment.
>
> The example inhttp://django-mptt.github.com/django-mptt/templates.htmlexplains
> it pretty well I think.
>
> Craig de Stigter
>
Reply all
Reply to author
Forward
0 new messages