Write a recursive loop in DotLiquid

I have this loop in DotLiquid :

{% for page in Page -%} {{ page.Title }} <ul> {% for subpage in page.Pages -%} <li>{{ subpage.Title }}</li> <!-- subpage.Pages has more pages and so on... --> {% endfor -%} </ul> {% endfor -%} 

Each subpage object has the Pages property with other subpages in the list (for example, the first Page object.

How to write a recursive iteration over these subpages to create a complete tree?

+4
source share
1 answer

Move your code to a separate file and use the include tag.

This related question includes some sample template code - it is for the Ruby version of Liquid, but it must be directly portable.

Depending on what you need to do, you can install Template.FileSystem in the built-in LocalFileSystem to allow inclusions or create your own. See the source code for LocalFileSystem for an example implementation of IFileSystem .

+3
source

Source: https://habr.com/ru/post/1436274/


All Articles