If statement for entries

127 Views Asked by At

In Movable Type is there a way to get see if there are entries with a certain tag and if there is do one thing and if not do another?

For instance do the following but only display the h1 tag if there is actually an @feature entry. If there is not then display something else? Because hello will display regardless of the number of entries that have the @feature tag.

<mt:Entries tag="@feature" lastn="1">
<h1>hello</h1>
<mt:EntryBody$>
</mt:Entries>
1

There are 1 best solutions below

0
On

An mt:Entries loop that would return zero items doesn't process at all, rather than actually indicate there are no results. (This is not considered a bug, by the way.)

So, you sort of have to go around the system and build the test yourself:

<$mt:var name="featureflag" value="0"$>
<mt:Entries tag="sdfdsfsda" lastn="1">
    <mt:if name="__first__"><$mt:var name="featureflag" value="1"$></mt:if>
    <h1>hello</h1>
</mt:Entries>
<mt:unless name="featureflag">
<h1>No such entries</h1>
</mt:unless>