[dev] Template question

Marko Djukic marko at oblo.com
Fri May 9 19:50:47 PDT 2003


yes, nested loops are possible. for example:

<loop:listitems>
  <tag:listitems.foo />
  <tag:listitems.bar />
    <loop:sublist>
      <tag:sublist>
    </loop:sublist>
</loop:listitems>

or to do an even more complex example, to include also nested tags...
in your script set up the vars:
$categories = array('fruit', 'veggie', 'thing');
$subcats = array('fruit' => array('apple', 'pear'),
                 'veggie' => array('tomato', 'potato', 'carrot', 'onion'),
                 'thing' => array('spoon', 'paperbag', 'tool'));
$template->set('categories', $categories);
foreach ($categories as $c) {
    $template->set('subcat_' . $c, $subcats[$c]);
}

then in your template do:
<table>
<loop:categories>
<tr>
  <td>
    I have a <tag:categories />. What could it be?
  </td><td>
    <ul>
    <loop:subcat_<tag:categories />>
      <li><tag:subcat_<tag:categories /> /></li>
    </loop:subcat_<tag:categories />>
    </ul>
  </td>
</tr>
</loop:categories>
</table>

and you get an output:
I have a fruit. What could it be?    * apple
                                     * pear

I have a veggie. What could it be?   * tomato
                                     * potato
                                     * carrot
                                     * onion

I have a thing. What could it be?    * spoon
                                     * paperbag
                                     * tool

marko

Quoting Mario Andres Yepes C <marioy at upb.edu.co>:

>
> Is it posible to have nested loops in a Horde_Template file? if so, what
> commands should I issue or how should I proceed.
>
> Thanks in advance
> Mario
>
> --
> Horde developers mailing list
> Frequently Asked Questions: http://horde.org/faq/
> To unsubscribe, mail: dev-unsubscribe at lists.horde.org
>




More information about the dev mailing list