OpenWGA 7.6 - WebTML reference

WebTML tags » foreach

<tml:foreach offset ="1..n">

Purpose:

Specifies an offset from which the foreach tag should start iteration and paging computation

Description:

The offset attribute  takes a number as value which specifies the number of iteration value from which iteration should start. All previous values are skipped and not put out. An offset number of 1 means the very first iteration value, 2 the second one and so on.

The offset attribute can be combined with the pagesize attribute where also page 1 will start at the offset and all following pages are calculated accordingly.

Value(s):

A number with 1 being the offset for first iteration value

Default value:

1

Examples:

The offset attribute can use in a number of different ways. It can be used to skip a certain amount of iteration values by simply setting the offset beyond them. For example if you want to display some first n results in a special way. You could create two <tml:foreach> tags where the second one uses the offset attribute to start at the position where the first one ended:

<tml:collection>

    <tml:query type="hql"> ... some query ... </tml:query>


    <tml:foreach pagesize="3">

         

       ... headline news display ...  


    </tml:foreach>


    <tml:foreach offset="4" pagesize="5">

         

       ... other news display ...  


    </tml:foreach>


</tml:collection>

It also can be used a to create a customized paging functionality that works different than the built-in one. For example a paging that always goes back&forth 10 results. We cannot use the normal paging functionality here but need some programming to calculate the offset accordingly. So we use a WebTML variable "myOffset" to control the offset, which is set to +-10 on URL clicking:

<tml:script>

if (!isDefined("myOffset")) {

  myOffset = 1;

}

</tml:script>

<tml:collection>

   <tml:query type="hql"> ... some query ... </tml:query>

   <ul>

     <tml:foreach offset="{item:myOffset}" pagesize="50" linear="true">

      <li><tml:link/>    

     </tml:foreach>

   </ul>

</tml:collection>

<a href="<tml:url><tml:param name="myOffset" expression="myOffset - 10"/></tml:url>">Ten results back</a>

 - - - 

<a href="<tml:url><tml:param name="myOffset" expression="myOffset + 10"/></tml:url>">Ten results forward</a>