Movable Type Enterprise Documentation

« MTCategoryBasename | Up | MTCategoryPrevious »

Chapter Category

MTIfCategory

A conditional block which tests attributes of the category currently in context and outputs its contents on a match.

This tag can be used anywhere where there is a category context:

  • Within an MTEntries loop
  • In a category archive template
  • Within an MTCategories loop
  • Etc

Required attributes

  • name - Name of category for conditional test
  • label - Alias of name attribute above

Optional attribute

  • type - Tests for the assignment type for the category, accepting values of primary and secondary.

NOTE: There is currently a known issue related to this in that the value of 'secondary' is not accepted by the type attribute.

Example code

Conditional output based on category:

<MTIfCategory label="important">
    This is important
<MTElse>
    Misc is not so important
</MTElse>
</MTIfCategory>

This can be used in conjuction with CSS rules to display things differentially. This adds a class attribute of featured to the entry title h2 tag if the category of the entry is "Featured":

<h2 <MTIfCategory name="Featured">class="featured"</MTIfCategory>>
   <MTEntryTitle>
</h2>

Below is a full example testing for not only category assignment, but also the type of assignment.

<MTIfCategory label="misc" type="primary">
    Misc is the primary category
<MTElse>
    <MTIfCategory label="misc" type="secondary">
        Misc is the secondary category
    <MTElse>
        Misc is neither a primary not secondary category
    </MTElse>
    </MTIfCategory>
</MTElse>
</MTIfCategory>

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.