Home > Articles > Web Development > Content Management Systems

  • Print
  • + Share This
This chapter is from the book


The default Drupal core engine comes with a module that allows you to search the contents of your site. There are four steps to enabling search on your site: enable the search module; update the permissions for users to search content; index the content on a regular basis through the use of a “cron job”; and display the search form to site visitors.

  1. The Search module is not enabled by default. To enable this module, navigate to Administer, Site Building, Modules; enable the module by placing a check mark next to it, scrolling to the bottom of the Web page, and clicking “Save.”
  2. Next you must enable the permissions for the appropriate roles in your site. Navigate to Administer, User Management, Permissions. To enable searching for all users, make sure “search content” and “advanced search” are enabled for “anonymous user.”
  3. Drupal’s search module does not search the content of the database directly because this operation would be too time-consuming. Instead, it searches an index of your content (similar to an index at the back of a book). To initiate this process of creating or updating the index, navigate to Administer, Reports, Status report. Click on the link “run cron manually.” The page will automatically refresh, showing you the cron maintenance task that was last run “less than a few seconds ago.” For more information on configuring cron jobs for Drupal, refer to Chapter 2.
  4. Two styles of search tools are available for Drupal themes; Figure 4.8 compares these two search forms. On the left side of the screen, the top option is the theme’s search box (which has no heading); the second option is the Search form block (which has a heading). If you like, you can customize the Search form block to remove the heading. Although these two search forms have a very similar appearance, they are actually applied in quite different ways. The Search form block may be placed only into an existing region; in contrast, the theme’s search box may be placed anywhere within the page template.

    Figure 4.8

    Figure 4.8 There are two ways to enable a search box in a Drupal theme. On the left side of the screen, the top option is the theme’s search form; the bottom option is the Search form block.

To enable the theme’s search box, add the following PHP snippet to your theme’s page.tpl.php file at the appropriate location:

<?php print $search_box ?>

To enable the search block, use these steps:

  1. Navigate to Administer, Site Building, Blocks.
  2. Scroll down to the “Disabled” section.
  3. Select a region for the search form from the select menu.
  4. Scroll to the bottom of the Web page and click “Save blocks.”

Your search box should now appear as a block within your Web site. To further customize the options for the search block, you can navigate to Administer, Site building, Blocks and click on the “configure” link next to the Search form.

  • + Share This
  • 🔖 Save To Your Account