<tpl:LoopPosition>

The template tag tpl:LoopPosition tests the actual state of a loop such as <tpl:Entries>, and allows execution of the included code as long as the condition's attributes are verified.

Note:

All template tags generating a loop on a recordset (posts, categories, archives, languages, comments, trackbacks) may be tested by this template tag.

Attributes

start

This attribute defines the start index from which the condition will be tested. Its value may be negative, in which case it will apply to the amount of remaining iterations.

  • start="2" → condition will be tested as from the second iteration
  • start="-2" → condition will be tested for the last 2 iterations

length

This attribute defines the amount of iterations for which condition will be tested. Its value may be negative, in which case it defines the total amount of iterations minus its value.

  • length="3" → condition will be tested for 3 iterations
  • length="-3" → condition will be tested until there are 3 iterations left

even

This attribute defines the parity on which the condition is tested.

  • even="1" → condition will be tested on even iterations
  • even="0" → condition will be tested on odd iterations

Examples

Display title for each post in the loop, and content only for the first 3 posts

<tpl:Entries>
  <h3>{{tpl:EntryTitle}}</h3>
  <tpl:LoopPosition start="1" length="3">
    <div class="post-content">{{tpl:EntryContent}}</div>
  </tpl:LoopPosition> 
</tpl:Entries>

Display only last 2 posts

<tpl:Entries>
  <tpl:LoopPosition start="-2">
    <h3>{{tpl:EntryTitle}}</h3>
    <div class="post-content">{{tpl:EntryContent}}</div>
  </tpl:LoopPosition> 
</tpl:Entries>

Display all tags separated by commas

<tpl:Tags>
	{{tpl:TagID}}<tpl:LoopPosition start="1" length="-1">, </tpl:LoopPosition>
</tpl:Tags>

In this code, <tpl:LoopPosition> allows to separate tags by comas, without having a coma after the last tag because of the attribute length="-1".

Wiki powered by Dokuwiki.