La balise tpl:LoopPosition teste l'état actuel de parcours d'une boucle initiée au préalable par une boucle <tpl:Entries> ou équivalent et permet de traiter le code sous-jacent tant que la condition définie par les attributs est vérifiée.
Tests sur la variable loop, en l'occurrence loop.index et loop.revindex.
<tpl:Entries>
<h3>{{tpl:EntryTitle}}</h3>
<tpl:LoopPosition start="1" length="3">
<div class="post-content">
{{tpl:EntryContent}}
</div>
</tpl:LoopPosition>
</tpl:Entries>
{% for p in POSTS %} <h3>{{ p.title }}</h3> {% if loop.index <= 3 %} <div class="post-content"> {{p.content}} </div> {% endif %} {% endfor %}
<tpl:Entries>
<tpl:LoopPosition start="-2">
<h3>{{tpl:EntryTitle}}</h3>
<div class="post-content">
{{tpl:EntryContent}}
</div>
</tpl:LoopPosition>
</tpl:Entries>
{# Traduction "à la lettre" de la boucle à gauche #} {% for p in POSTS %} {% if loop.revindex <= 2 %} <h3>{{ p.title}}</h3> <div class="post-content"> {{p.content}} </div> {% endif %} {% endfor %}
{# version optimisée #} {% for p in POSTS|slice(-2) %} <h3>{{ p.title}}</h3> <div class="post-content"> {{p.content}} </div> {% endfor %}
<tpl:Tags>
{{tpl:TagID}}
<tpl:LoopPosition start="1"
length="-1">, </tpl:LoopPosition>
</tpl:Tags>
{{ TAGS|join(', '}}
Wiki powered by Dokuwiki.