Applications

RightFields 1.21

Spam Prevention

TinyTuring 1.02

Template Tags

CheckLinks 1.2

Collect 1.2

Columnize 1.11

Compare 1.1

DateTags 2.3

DaylightOrStandard 1.1

DropCap 1.1

FilterCategories 1.1

FirstNWords 1.3

GetXML 1.1

Glue 1.1

IfModified 1.4

Loop 1.1

TextWrap 1.1



Support staggernation.com's plugin development

Loop Plugin for Movable Type

Current version: 1.1 (7/12/04)

About the Loop Plugin

This Movable Type plugin implements a set of template tags for looping through a list of values, repeating a portion of a template for each value in the list.

Installation

To install the Loop plugin, upload the file Loop.pl to the plugins directory within your Movable Type directory. If you do not already have a plugins directory, create one before uploading the file. For more information about Movable Type plugins, see the documentation.

Support

Please use the support forums for all support requests, bug reports, feature requests, questions, and comments regarding this plugin.

MTLoop

This container tag will output its contents once for each value in the list of values you specify in the values attribute. By default, the plugin will assume the values are separated by commas. If your values are separated by a different string, you can indicate that with the delimiter attribute. Other Movable Type tags can be used within the values list; some examples of this are below.

Inside MTLoop, use MTLoopValue to output the value for a given iteration of the loop, and MTLoopN to output the number of the iteration. If you want to pass the value as an attribute to another tag, simply use square brackets instead of angle brackets (and no dollar signs): [MTLoopValue].

The following example will create links to the last three entries by each of four different authors:

<MTLoop values="Bob,Carol,Ted,Alice">
<p>Recent Entries by <$MTLoopValue$>:<br>
 <MTEntries author="[MTLoopValue]" lastn="3">
  <a href="<$MTEntryLink$>"><$MTEntryTitle$></a><br>
 </MTEntries>
</MTLoop>

The tag takes the following attributes:

  • values="list" (required)
    The list of values to be looped through. You can include MT template code in this attribute, using square brackets instead of angle brackets (and no dollar signs) and single quotes instead of double quotes. (To include a literal square bracket or single quote, escape it with a backslash.) For instance, the following example would load the template module Category List and use its contents as the list of values, printing the last three entries in each category:
    <MTLoop values="[MTInclude module='Category List']">
     <p>Recent Entries for "<$MTLoopValue$>"<br>
     <MTEntries category="[MTLoopValue]">
      <a href="<$MTEntryLink$>"><$MTEntryTitle$></a><br>
     </MTEntries>
    </MTLoop>
    
  • delimiter="string" (optional)
    If you pass this attribute, the plugin will treat the values attribute as a list separated by string.

    You can pass \n to loop through the lines of a field. For example, if you have entries that consist of source code, you can use the following to output the code with line numbers:

    <MTEntries category="Code">
     <code><MTLoop values="[MTEntryBody convert_breaks='0']" delimiter="\n">
      <$MTLoopN$>: <$MTLoopValue$><br>
     </MTLoop></code>
    </MTEntries>
    

MTLoopValue

Within MTLoop, outputs the value of the current iteration of the loop.

You can actually use the value (in square brackets, without dollar signs) as part of the name of another MT tag. Here's a compact way of dumping a bunch of information for an entry (something like this might be useful for an export template):

<MTEntries>
 <p><MTLoop values="Title,Status,Excerpt,Body,More,Link,Author,Date,CommentCount,TrackbackCount,ID,Category">
  <b><$MTLoopValue$>:</b><br>
  <$MTEntry[MTLoopValue]$><br>
 </MTLoop>
</MTEntries>

MTLoopN

Within MTLoop, outputs the number of the current iteration of the loop.

Version History

7/12/04 - version 1.1

  • Plugin now registers itself with MT 3 interface.
  • Added $VERSION variable and package declaration.
  • All container tags now pass conditions along when building contents, so they'll work outside conditional tags within MTEntries, etc.

8/15/02 - version 1.0 released


The End As I Know It: A Novel of Millennial Anxiety, by staggernation.com proprietor Kevin Shay, is now available in paperback.

Please visit kshay.com for more information.