Template Loop Meta Variables

Movable Type exposes a number of different template tags called container tags that loop over a set of objects. This allows designers to display for example the last 10 entries on a blog, or to display each of the comments associated with an entry.

As Movable Type iterates or loops over a list of objects in this fashion it maintains a number of meta variables for you, allowing you to test if the current item is an odd or even item in the list for example.

Loop Meta Variables

Note: Each of these variables is preceded and followed by two (2) underscores.

  • __even__ - returns true if the current item in the list is even
  • __odd__ - returns true if the current item in the list is odd
  • __first__ - returns true if the current item in the list if the first item in the list
  • __last__ - returns true if the current item in the list if the last item in the list
  • __counter__ - returns the index of the current item in the list

Examples

List the most recent 10 entries in a unordered list. Adding "odd' and "even" classes. Note the order in the list in parenthesis:

<mt:Entries lastn="10">
    <mt:if name="__first__"><ul></mt:if>
    <li class="entry <mt:if name="__even__">even<mt:else>odd</mt:if>">
        <mt:EntryTitle> (<mt:var name="__counter__">0
    </li>
    <mt:if name="__last__"></ul></mt:if>
</mt:Entries>
This page was last updated on 2009-06-23, 22:01. [Edit]

3 Notes

This should really be linked from each of the relevant loops, such as Entries. A lot of people don't know about them, and right now, it's being relied upon for them to come into the designer's guide, which presumes a certain interpretation, eg. in most of my client relationships, I would probably identify as the admin, not designer.

Thanks Su. I've added a link under Related Entries on all the major loop/block tags in the documentation, and added the tag "block" to this page.

FYI: These meta-variables are not available under dynamic publishing.

Leave a note

Have a question? Please use the MT Forums. Notes submitted on documentation should pertain to tips & hints regarding documentation. Your note may be removed once its contents have been integrated into the body of the page.