<mt:NoSearch>

A container tag whose contents are displayed only if there is no search performed.

This tag is only recognized in search templates.

This page was last updated on 1969-12-31, 16:00. [Edit]

1 Note

There's a problem with this tag in version 4.2+. See the forum thread and fogbugz.

It seems nosearch doesn't do very much in this release, and the fix is scheduled for integration into the next.

Meanwhile, you can actually use the <mt:if>, <mt:else>, <elseif> and <mt:unless> conditional tags to get this to work.

Basically, you run <mt:if> to test whether the search string evaluates to an empty string, i.e., whether it has a single alphanumeric character in it. You do this by using a regular expression in <mt:if>, so:

<mt:if tag="searchstring" like="/\w/">

The logic is this:

  1. If the search string has some term in it, then:
    a. show the results if any are found; or
    b. show no results found for that string;
  2. If the search string does not have a search term at all (the string is empty), fire the <mt:nosearch> code chunk.

Finally, if <mt:searchresultcount> evaluates to zero (there are no search results; which is true whenever nothing is found and also when nothing is specified to find), display instructions.

Example:

    <mt:if tag="searchstring" like="/\w/">
        <MTSearchResults>
            <MTBlogResultHeader>
                <MTIfTagSearch>
                    <h2>Results for: <mt:searchstring></h2>
                </MTIfTagSearch>
                <MTIfStraightSearch>
                    <h2>Search Results for: <mt:searchstring></h2>
                </MTIfStraightSearch>
            </MTBlogResultHeader>
            <ul>
                <li>
                    <b><a href="<MT:EntryPermalink>" title="<MT:EntryTitle>"><mt:EntryTitle></a></b><br />
                    <mt:Entrybody />
                </li>
            </ul>
        </MTSearchResults>

        <MTNoSearchResults>
            <h2>Searched for <mt:searchstring></h2>
            <p>No entries were found containing <mt:searchstring></p>
        </MTNoSearchResults>

        <mt:else>

        <MTNoSearch>
            <h2>Nothing to search!</h2>
            <p>You didn't say what you're looking for. Perhaps you need to find yourself first?</p>
        </MTNoSearch>

        </mt:else>
        </mt:if>

        <mt:if tag="searchresultcount" eq="0">
            <h3>Instructions</h3>
            <p>By default, this search engine looks for all words in any order. To search for an exact phrase, enclose the phrase in quotes:</p>

            <blockquote>
                "<code>movable type</code>"
            </blockquote>

            <p>The search engine also supports <code><b>AND</b></code>, <code><b>OR</b></code>, and <code><b>NOT</b></code> keywords to specify boolean expressions:</p>

            <blockquote>
                <code>publishing <b>OR</b> personal</code>
            </blockquote>

            <blockquote>
                <code>publishing <b>NOT</b> dynamic</code>
            </blockquote>
    </mt:if>

Leave a note

Have a question? Please use the MT Forums. Notes submitted on documentation should pertain to tips & hints regarding documentation. Your note may be removed once its contents have been integrated into the body of the page.