Movable Type Documentation > Designer's Guide

Variable Interpolation

Movable Type allows for designers and developers to embed variables inside of other template tags. This gives them the flexibility of having a single tag produce a variety of outputs depending upon its context or what variables are passed into it. For example, say you wanted to display a list of related entries based upon what entry the reader happen to be looking at. You wanted to do this by finding the most recent entries from categories shared by the current entry. Make sense?

Let's compare two examples. The first displays a list of entries tagged "news" or "current events."

<ul>
<mt:entries tags="News OR Current Events">
<li><a href="<mt:entrypermalink>"><mt:entrytitle></a></li>
</mt:entries>
</ul>

Now, let's tweak that template code to display a list of entries using a variable to select which tags to filter the list by:

<mt:setvarblock name="tags"><mt:entrytags glue=" OR "/></mt:setvarblock>
<ul>
<mt:entries tags="$tags">
<li><a href="<mt:entrypermalink>"><mt:entrytitle></a></li>
</mt:entries>
</ul>

In this example, the variable is denoted using the dollar sign ($) followed by the variable name. Note that the dollar sign is not needed when declaring the variable using the <mt:SetVarBlock> template tag.

Starting with Movable Type 4.0, all template tag attributes can process variables in this fashion, opening the door for far advanced and adaptive templates.

This page was last updated on 2007-12-11, 17:00.  

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.)