The Movable Type User Manual

NOTE: This documentation is for Movable Type 3.2. If you are using a newer version, please see the documentation for Movable type 3.3x or Movable Type Enterprise.

« Customize the Default Search Template | Up | Setting Up Google Enabled Entries »

Chapter 10: Search

Adding Alternate Search Templates

Problem

You want to use an alternate design or layout for the search results returned by Movable Type's public search engine.

Solution

Create the template and use the AltTemplate configuration directive to define its use.

Discussion

Typically, when a search is performed, the default template, search_templates/default.tmpl, is rendered to display the results. The built-in search can perform a comment search in which the template search_templates/comments.tmpl is used.

However, if you have multiple weblogs that employ the search functionality, you may very well want the search results from one weblog to look different from that of another. To do this, you can use alternate search templates.

  1. Create the template file

    For each different look-and-feel that you want, create a search results template file, and put them in your `search_templates/ directory.

    Usually, the best thing to do if you're starting out is to make a copy of search_templates/default.tmpl called, for example, search_templates/my_customized_search.tmpl and use that as a starting point. Of course, the name of the template is totally up to you and your visitors will never see it.

  2. Tell Movable Type about it

    Open up your mt-config.cgi file in a text editor, and use the AltTemplate configuration directive to tell Movable Type about your new search template and the template file to use in rendering it.

    For example, if you have two weblogs, "Work," and "Play," and you want each weblog to have its own search results template, you might add something like this:

    AltTemplate work work.tmpl
    AltTemplate play play.tmpl

    These two lines tell Movable Type that when the work template is requested in a search query, it should use the work.tmpl template file to display the results and that when the play template is requested, it should use the play.tmpl template file.

  3. Search, customize, and reload

    At this point, you're probably going to want to customize your new template before unleashing it on the world.

    To do so, take the following URL:

    http://www.example.com/path/to/mt-search.cgi?Template=NAME

    ...and substitute the placehoders above with the:

    • correct domain and path to mt-search.cgi for your installation
    • template name you chose in the previous step for NAME.

    When the page loads, it should be showing your template, which you can edit and reload as many times as you like without ever affecting your visitors. If you've edited your blog templates before, the search templates will feel very familiar to you except that, in addition many tags you're used to, they also use the special search template tags.

    Once you have it just right, move on to step 4.

    Notes: If you get an error like "No alternate template is specified for the Template 'work'", check the AltTemplate setting in your mt-config.cgi file and make sure that both the template name is identical to the one used in the URL and that that the template filename is identical to the file in search_templates folder.

  4. Configure the search form

    Now that your search template is perfect, it's time to let the world use it in their searches. If you don't already have a search form on, for example, on your main index, see "Creating a search form".

    To use your new template in your search form, specify it a hidden form input. Anywhere between the <form ...> and </form> tags, add the following substituting your template name for NAME:

    <input type="hidden" name="Template" value="NAME" />

    If you wish to restrict the search to just this one weblog, you may also
    want to add a hidden IncludeBlogs paramter with the blog ID like so:

    <input type="hidden" name="IncludeBlogs" value="<$MTBlogID$>" />

Related

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 Support.

Six Apart
Makers of weblog software and services for individuals, organizations and businesses.
This website is powered by Movable Type.