Home > The Template System > Repeating Blocks

Table of Contents

DotAdmin User Guide

Repeating Blocks

For some page elements, the same mark-up needs to be repeated multiple times for multiple rows of content. The most common elements that repeat are things like links in a menu, or the contents of a shopping cart. To repeat a section of mark-up, the template system uses a pair of BLOCK markers enclosed in HTML comment tags:

<!-- BLOCK {pagelist} -->
  <a href="/{id}">{title}</a><br>
<!-- /BLOCK {pagelist} -->

The above example shows a repeating block, named "pagelist", which generates a list of links.

All instructions, with the exception of placeholders, are formatted using HTML comments in this way. Instructions are always UPPERCASE, and note that the closing marker is always preceded with a forward slash: /BLOCK.

Note: Where a block appears in a template, but the CMS cannot find any content to populate that block, it is ignored and the HTML inside the block never appears.

Varying the Appearance of Blocks

The rows of content produced from a BLOCK don't all have to look the same. Using the LINE instruction, you can provide alternating chunks of HTML for each successive block.

The LINE instruction is formatted in the same way as the BLOCK instruction, using a pair of HTML comment tags, but instead of providing an identifying name as you would for a BLOCK you must provide a numeric ID which increments for each line, starting with LINE 1.

<table>
<!--BLOCK {pagelist} -->

  <!--LINE 1-->
  <tr>
    <td style="background-color: #333333;">
      <a href="/content/{id}">{title}</a>
    </td>
  </tr>
  <!--/LINE 1-->

  <!--LINE 2-->
  <tr>
    <td style="background-color: #FFFFFF;">
      <a href="/content/{id}">{title}</a>
    </td>
  </tr>
  <!--/LINE 2-->

<!-- /BLOCK {pagelist} -->
</table>

A striped table.

In this example, the LINE instruction is used to change the background colour of neighbouring table rows in a repeating BLOCK, to create a striped table. The whole of BLOCK {pagelist} repeats once for every two rows of content it outputs.