When displaying the search form in my header, what is the preferred method to use if it cannot fit into my header region??
should I...
- create a custom region?
- use some ki开发者_StackOverflow中文版nd of 'print $search_form'
- drupal_get_form()??
- use the theme() function??
please help! I'm new to Drupal and trying to figure out the best 'Drupal Way' of doing things.
Depends on how you want to define or maintain the search form. If you think of it as part of the theme (that is, it's as static as the page background or colors), consider just using the following in page.tpl.php
:
<?php if ($search_box): ?>
<?php print $search_box ?>
<?php endif; ?>
This is de-facto the Drupal Way: if your theme didn't modify the page variables, you get $search_box
for free in page.tpl.php
. Adding the conditional also lets site maintainers turn it off in the theme settings and specify permissions for it.
If you want to give site maintainers the ability to move it around from region to region, consider using the Search block. This way it can be utilized just as any other block on your site. This would also be considered Drupal Way-ish: you get the block for free if you enable the Search module.
If you want theme the forms, override search-theme-form.tpl.php
if you use the first method, and search-box-form.tpl.php
if you used the second. Both templates can be found in modules/search
.
You could do any of those. You could create a custom region, and use CSS to change the display. You could alter the form with preprocessing hooks or hook_form_alter.
Depends on whatever is easiest for you.
精彩评论