Search code examples
movabletype

Movable Type 4: IF / Else logic "if Entry"


I would like to have logic in the Meta Description (located in Banner Header) tag that has the following effect:

if rendering an Entry:

     <meta name="description" content="<$mt:EntryBody words="25"$>..." />
else:

     <meta name="description" content="<$mt:BlogDescription$>" />

Thanks for your help!


Solution

  • IfArchiveType is fine if you know you're only going to be doing one test.
    With a meta description, on the other hand, there's a good chance you'll want to do something different on category pages, say. While you could just pile up individual IfArchiveType tests for each, you'd do better to familiarize yourself with the archive template variables(which provide a lot more besides) and use the generalized If/Else|If tags:

    <mt:if name="entry_archive">
        <meta name="description" content="[Entry archive-specific description]" />
    <mt:elseif name="category_archive">
        <meta name="description" content="[Category archive-specific description]" />
    <mt:else>
        <meta name="description" content="[Site-wide fallback description]" />
    </mt:if>
    

    ...which can then be further cleaned up using the Var tag:

    <mt:if name="entry_archive">
        <$mt:var name="metaDesc" value="[Entry archive-specific description]"$>
    <mt:elseif name="category_archive">
        <$mt:var name="metaDesc" value="[Category archive-specific description]"$>
    <mt:else>
        <$mt:var name="metaDesc" value="[Site-wide fallback description]"$>
    </mt:if>
    
    <meta name="description" content="<$mt:var name="metaDesc"$>" />
    

    [For clarity, I've omitted the modifiers Mike added, but they are a good idea to include.]