Smarty Template question: Is there a fast way to transform a JSON structure into a unnumbered list?

I have a JSON structure like this:

{
    "items": [
        {
            "name": "A",
            "items": [
                {
                    "name": "A1",
                    "items": []
                },
                {
                    "name": "A2",
                    "items": []
                },
                {
                    "name": "A3",
                    "items": []
                }
            ]
        },
        {
            "name": "b",
            "items": [
                {
                    "name": "B1",
                    "items": []
                },
                {
                    "name": "B2",
                    "items": []
                },
                {
                    "name": "B3",
                    "items": []
                }
            ]
        }
    ]
}

The structure can go much deeper, but you get the idea. And I want it to become a HTML-list like this:

<ul>
    <li>
        A
        <ul>
            <li>A1</li>
            <li>A2</li>
            <li>A3</li>
        </ul>  
    </li>
    <li>
        B
        <ul>
            <li>B1</li>
            <li>B2</li>
            <li>B3</li>
        </ul>  
    </li>
</ul>  

I created a function in the template which calls itself within a foreach loop. This creates the correct HTML list structure, but it is slow compared to other things done in the template. Especially when JSON structure is large and is many levels deep. So I was wondering if there is a better/faster way to do this.



Read more here: https://stackoverflow.com/questions/65700406/smarty-template-question-is-there-a-fast-way-to-transform-a-json-structure-into

Content Attribution

This content was originally published by ted at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: