Menu

Loops inside loops

2002-06-17
2002-06-28
  • Anton Kokarski

    Anton Kokarski - 2002-06-17

    Hi,

    is it posible to have loop inside another loop in a template?

    Thank you,
    Anton

     
    • Philip S Tellis

      Philip S Tellis - 2002-06-28

      yes.

      each loop is just a vector, and the elements of the vetctor are hashtables.

      if one of the elements of the hashtable is another vector, you have yourself nested loops.

      Template t = new Template(...);
      Vector v = new Vector();

      Vector v2 = new Vector();
      // add some elements to v2
      Hashtable h = new Hashtable();
      h.put("loop2", v2);
      h.put("var1", "variable");
      v.addElement(h);
      t.setParam("loop1", v);

      and your template looks like this:

      <tmpl_loop loop1>
          <tmpl_var var1>
          <tmpl_loop loop2>
                  vars from loop2
          </tmpl_loop>
      </tmpl_loop>

       

Log in to post a comment.