5. Other section types

Nesting sections and playing with data format are just the beginning of the real fun. Although the ordinary, linear lists are the most common, they do not cover all the situations and problems. Actually, opt:section is only the one of a couple of instructions called sections. The rest of them are:

  1. opt:selector - a connection of sections and switch statement. We can define several ways to render an element.
  2. opt:grid - displays elements in columns.
  3. opt:tree - renders tree data, lists with unlimited number of nesting levels.

What is more, they can cooperate one with another. For example, if we nest opt:grid within opt:section, the compiler still creates a connection between them, identical as those shown in previous chapters. Let's take a look what sections really can do. Below you can find a template for an image gallery:

<table class="gallery">
  <opt:grid name="images" cols="5">
     <opt:item><td><img parse:src="$images.picture" /></td></opt:item>
     <opt:emptyItem><td> </td></opt:emptyItem>

Writing the some code in pure PHP would give us a classic example of a write-only code. Fortunately, OPT frees the template designers from dealing with technical details. We simply define, how the element with a photo should look like, and how - the empty element used in the last row to complete the table if the number of photos is not a multiplicity of a column number.

We encourage to explore the other section types.