Front End Drupal: Designing, Theming, Scripting
Search
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.
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."
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."
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.
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.
Click here for larger image
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:
- Navigate to Administer, Site Building, Blocks.
- Scroll down to the "Disabled" section.
- Select a region for the search form from the select menu.
- 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.
Changing Templates
In this chapter you have learned how to create a template
for your page and how to customize the page elements. In
this section you will see how to change the page templates
that are used for different sections of your Web site. You
may want to use different templates for each of the
following tasks and types of pages:
- Editing content
- Displaying a content type
- User login
- Front page
- Categories
- Offline or maintenance page
Some of these templates are provided by default; others
you will need to build from scratch. The online
documentation has a complete list of all default templates
provided by Drupal at http://www.drupal.org/node/190815.
This section describes several of the page-specific template
options.
Assigning themes to different parts of your site - This
section describes how to change the template that is used
within a single theme. If you need to assign whole themes to
different parts of your Web site, you will need a more
powerful toolkit. The contributed module known as sections
will allow you to do exactly this. For more information
about this project, visit http://
drupal.org/project/sections%3C/a.
If you need to provide even more customization on a per-
section basis, you may need The Organic Groups module. This
module enables authorized users to create and manage their
own "groups." Each group gets its own theme, language, and
taxonomy. The techniques described in this book could be
applied to each theme for each group on the Web site. For
more information about this project, visit http://drupal.org/
project/og.
Blocks
Drupal Front End
Custom Front Page
|