What about a recursive macro?

<ul metal:define-macro="somelist" tal:condition="php:count(elements)">
    <li tal:repeat="element elements">
        <tal:block tal:condition="php:is_array(element)">
            <tal:block tal:define="elements element"/>
        </tal:block>
        <tal:block tal:condition="not:php:is_array(element)"
tal:content="element"/>
    </li>
</ul>

<tal:block tal:define="elements fruits" metal:use-macro="somelist"/>

Marco Pivetta
http://twitter.com/Ocramius
http://marco-pivetta.com



On 21 October 2011 21:59, GRolf <ger...@pictureparking.com> wrote:

>
> I have a multilevel array, where, as the template concerns, the number of
> levels is unlimited.
>
> eg
> $objects = array('Food'=>array('Fruit'=>**array('Red'=>array('Cherry',
> 'Strawberry'), 'Yellow'=>array('Banana')), 'Meat'=>array('Steak',
> 'Hamburger'));
>
> I'd like to loop through this array in my templates and end up with
>
> <ul>
> <li>Food
>  <ul><li>Fruit
>    <ul><li>Red
>      <ul><li>Cherre</li><li>**Strawberry</li></ul>
>    </li><li>Yellow
> ... etc
>
>
> How could I do this, without needing to know the number of levels?
>
>
> --
>
> GRolf
>
> ______________________________**_________________
> PHPTAL mailing list
> PHPTAL@lists.motion-twin.com
> http://lists.motion-twin.com/**mailman/listinfo/phptal<http://lists.motion-twin.com/mailman/listinfo/phptal>
>
_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to