<r:loop>, <r:loop:each>, <r:loop:index>, <r:item>, <r:item_count>

Repeats a block of content.

There are three types of loops that can be performed.

  1. Set number of iterations
  2. From one integer to another
  3. Over a delimited list of items

The attribute options for the loop depend on the type of loop being performed.

Examples

Set number of iterations:

<r:loop:each times="10">
This content will be repeated 10 times.
</r:loop:each>


From one integer to another:

<r:loop:each from="5" to="15">
  This content will repeat 10 times.
</r:loop:each>


Over a delimited list of items:

<ul>
<r:loop:each items="first,second,third,fourth" delimiter=",">
<li><r:item /></li>
</r:loop:each>
</ul>

The example above will generate the <ul> below:

  • first
  • second
  • third
  • fourth

The <r:item> tag can be used within the <r:loop:each> tag to access the value of the current item being processed by the loop. The delimiter attribute defaults to a comma.

Example using a custom page attribute for an attribute option:

The values for any of the attribute options can come from page attributes, custom page attributes, template variables, URL query parameters, or even page content regions.

<r:loop:each items="{$page_items_var}" delimiter="|">
<p><r:item /></p>
</r:loop:each>

If the page_item_var variable has been setup as a custom page attribute, and its value is 'one|two|three', then the following content would be rendered.

<p>one</p>
<p>two</p>
<p>three</p>

You can access the number of items for a loop with the <r:item_count> tag.

<r:loop items="foo,bar,baz">
<p>Item Count: <r:item_count /></p>
<r:each>
    <p><r:item /></p>
  </r:each>
</r:loop>

You can get the index of a loop like so:

<ul>
  <r:loop:each items="One, Two, Three, Four">
    <li>
      <a href="#">Item <r:item /> with an index of <r:index /></a>
    </li>
  </r:loop:each>
</ul>

Different from <r:item_count />, <r:index /> starts at zero and counts up. This has various programming applications. These tags must be used inside a loop.

Last updated on March 16, 2016.

We welcome all questions, feedback and bug reports. If you're having an issue, we usually need the following information:

  • A brief description of the issue
  • A link to the page where you saw the issue
  • Screenshots that illustrate the problem - How do I take a screenshot?

Kindly email CleanSlate@mail.wvu.edu for help or use the form on the request help page.