Welcome to MTTags.com. Hopefully, you'll discover that this a really easy place to find information about Movable Type Template Tags. If you think we could be doing something better, please let us know! If this is your first time here, be sure to stop by the information desk, because we've got a growing todo list that might already include what you were about to suggest.

<MTEntryIfTagged>

A conditional block which outputs its content if the entry in context has any entry tags defined. Optional Attributes:

  • tag - Allows a user to specify a particular tag to test.

Example code

The following iterates over MTEntries and, for any entries which have non-private tags assigned, prints out the entry title and all of the non-private tags that are assigned to the entry (glued together by a comma and a space)

<MTEntries>

    <MTEntryIfTagged>
        The entry "<$MTEntryTitle$>" is tagged: 
           <MTEntryTags glue=", "><$MTTagName$></MTEntryTags>
    </MTEntryIfTagged>
</MTEntries>

The following prints out the entry title for each entry in the MTEntries loop as well as an "Important" icon when the entry is tagged "Important":

    <MTEntries>
        <MTEntryIfTagged tag="Important">
            <img src="important.gif" alt="Important"/>
        </MTEntryIfTagged>

        <$MTEntryTitle>
    </MTEntries>

Like with all conditional blocks, you can use MTElse to handle the inverse situation. In the example below case, something is printed for each entry returned by MTEntries. If there are tags assigned to the entry, the output is the same as in the first example. If not, the entry title is printed along with a message indicating there are no tags.

<MTEntries>

    The entry "<$MTEntryTitle$>"
        <MTEntryIfTagged>
            is tagged: <MTEntryTags glue=", "><$MTTagName$></MTEntryTags>
        <MTElse>
            has no entry tags.
        </MTElse>

        </MTEntryIfTagged>
</MTEntries>

Naturally, you can also nest MTEntryIfTagged blocks to test for multiple individual tags or to test for a particular tag first and then for the presence of any tag.

Below is a complex example demonstrating multiple nested blocks and use of MTElse. It displays one of four images next to each entry title based on whether something is tagged "important" and then additionally tagged additionally "feature" or "bug":

<MTEntries>
    <MTEntryIfTagged tag="Important">
        <MTEntryIfTagged tag="Feature">
            <img src="important_feature.gif" alt="Important feature"/>
        <MTElse>
            <MTEntryIfTagged tag="Bug">

                <img src="important_bug.gif" alt="Important bug"/>
            <MTElse>
                <img src="important.gif" alt="Important"/>
            </MTElse>
            </MTEntryIfTagged>
        </MTElse>

        </MTEntryIfTagged>
    <MTElse>
        <img src="not_important.gif" alt="Not important"/>
    </MTElse>
    </MTEntryIfTagged>
    <$MTEntryTitle>

</MTEntries>

See the relevant section of Chapter 5.4 in the User and Administration Manual entitled "Using Template Modules" for more examples related to entry tags, including the creation of "tag clouds".

Also, please see the important performance note regarding where MTTags lists are best placed for optimum performance, also in Chapter 5.4 of the User and Administration Manual, under "Eliminating redundant publishing".