I've been trying to figure out how I'm gonna do recursion with Liquid. I have an app where I want to give users full control over the rendering of the menu. However, the menu is defined by a tree, thus the need for recursive functions in Liquid.
How would I go about this? After doing some reading, I was thinking I'd tackle it this way:
include
I was thinking of using include
this way:
<ul id='site_nav' class='nav'>
{{ include 'menu_item' with menu_items }}
</ul>
And the menu_item partial is this:
<li id='{{menu_item.dom_id}}' class='{{menu_item.css_menu_class}}'>
{{ menu_item.name }}
<ul>
{{ include 'menu_item' with menu_item.children }}
</ul>
</li>
However, since it's user editable, I'll need to hack Liquid to make it load partials from a database. Since that will take a lot more time to study, I wanted to ask first if anyone has tackled this problem before.
- If you have tackled this problem before, how did you render something recursively and allow it to be user editable?
- If you have not tackled this before, what way would you recommend I take? The way I detailed above?
Thanks in advance!