Output default thumbnail in Movabletype 4

In a recent website redesign I wanted to have a simple article photo thumnbnail beside the title in a recent articles list placed in the site’s sidebar.
Using Movabletype 4’s asset manager this is relatively painless to implement unless their happens to be no assets associated with that entry. In that case MT will output the title without thumbnail.
What I want to happen is MT to output a default thumbnail in those instances.
I spent a couple hours trying to get this to work until a kind member of the MT community forums gave me the template code below:

<mt:SetVarBlock name="fallbackthumb">[FALLBACK CONTENT]</mt:setvarblock>
<mt:Entries>
    <mt:EntryAssets setvar="postthumb">[DESIRED CONTENT]</mt:entryassets>
    <$mt:Var name="postthumb" _default="$fallbackthumb"$>
</mt:Entries>

This is how mine looked after replacing the bracketed content.

<ul class="featured clearfix"><mt:Entries lastn="8"><li><a href="<$mt:EntryPermalink$>"><mt:SetVarBlock name="fallbackthumb"><img src="<$MTBlogURL$>img/default.jpg" /></mt:setvarblock><mt:EntryAssets setvar="postthumb" type="image" limit="1"><img src="<mt:AssetThumbnailURL width="70" />" alt="<mt:assetlabel>"/></mt:entryassets>
    <$mt:Var name="postthumb" _default="$fallbackthumb"$><strong><$MTEntryTitle$></strong></a></li>
</mt:Entries></ul>


Leave a Reply