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.

<MTIfNonEmpty>

A conditional tag that displays its contents if the tag specified with the tag attribute returns a value (i.e. is not empty or null)

Note that a value of '0' is not considered a null value for this tag and will cause the its contents to be printed. If you want to test numerical return values, you should instead use MTIfNonZero.

Attributes:

  • tag - The tag name to evaluate (with or without the MT prefix)

Other attributes are possible. See third example below.

Examples:

The following will print the entry title as an h2 header if a title was given:

<MTIfNonEmpty tag="EntryTitle">
    <h2><$MTEntryTitle$></h2>
</MTIfNonEmpty>

As with all conditional tags, you can use the MTElse tag inside of MTIfNonEmpty to print something if the value of the tag is empty. Here's a brief example that you might use in an MTEntries block to nicely handle entries without categories:

Category: 
    <MTIfNonEmpty tag="EntryCategory">
        <$MTEntryCategory$>

    <MTElse>
        None
    </MTElse>
    </MTIfNonEmpty>

Finally, if you are testing the value of a tag that has one or more attributes, those attributes can be used with MTIfNonEmpty as well. So, for example, to test

<$MTEntryTitle remove_html="1"$>

you do the following:

<MTIfNonEmpty tag="EntryTitle" remove_html="1">
    <title><$MTEntryTitle remove_html="1"$></title>
</MTIfNonEmpty>

Related topics: