Movable Type Enterprise Documentation

« MTGetVar | Up | MTIfNonZero »

Chapter Utility

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:

For more details see the relevant section of Chapter 8 in the Users and Administrators Guide entitled "Conditional Tags".

You can download the Users and Administrators Guide here.

Submit Feedback on This Article

Your comments on how we can improve this article are appreciated; but please do not use the feedback form to submit support requests or question. We will not respond to or publish such queries submitted through this form. If you have a technical question or problem, visit Movable Type Enterprise Support.

Six Apart
Makers of weblog software and services for individuals, organizations and businesses.
This website is powered by Movable Type.