Movable Type Documentation > Designer's Guide

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. Listed below are all the meta variables Movable Type maintains:

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

Example

<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:var name="__counter__">. <mt:EntryTitle>
  </li>
  <mt:if name="__last__"></ul></mt:if>
</mt:Entries>

Related

This page was last updated on 2008-03-05, 16:54.  

3 User Contributed Notes

Su Author Profile Page said:

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.

Beau Smith Author Profile Page said:

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.

Su Author Profile Page said:

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

Submit a User Contributed Note

User contributed notes are a great way to share the knowledge you have gained in using Movable Type.

If you have a technical question or problem, please visit Movable Type Support.

(If you haven't left a note here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)