By rogdawg on
I know this is a dumb question but, I need to ask it because I haven't found an example of how to do it...
I am creating a theme that has a horizontal navigation bar between the header and the content (like a million other sites). I have this code, that prints the navigation bar and attempts to print the search form:
<div id="nav" class="container_12">
<?php if ($page['navigation'] || $main_menu): ?>
<div id="navigation" class="grid_8 alpha">
<?php print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu',
'class' => array('links', 'inline', 'clearfix'),
),
'heading' => array(
'text' => t('Main menu'),
'level' => 'h2',
'class' => array('element-invisible'),
),
)); ?>
<?php print render($page['navigation']); ?>
</div><!-- /#navigation -->
<?php endif; ?>
<div id="search" class="grid_4 omega">
<?php print $search_form; ?> <!-- I also tried "<?php print render($search_form); ?>", with no luck -->
</div>
</div>
The navigation bar prints as expected but, the search_form does not appear. I have thoroughly searched all the resources I have (I think), and haven't found a solution, which tells me I am probably attempting to do this in an incorrect (dumb) way.
Thanks, in advance, for any advice you can give me.
Comments
changing my approach
OK. In stead of using the structure from the Zen theme that I start with, I have decided to define my own regions, and try to do this the proper way. So, I have defined the following regions for my site pages:
regions[header] = Header
regions[page_nav] = Page navigation
regions[content] = Content
regions[sidebar] = Sidebar
regions[footer] = Footer
and I have the following code to print the navigation in one area, and the search box in another area:
In Home > Administration > Structure, I have assigned the Navigation block and the Search form block to the Page navigation region. According to the page here: http://api.drupal.org/api/drupal/modules--search--search-block-form.tpl.... it seems I should be able to use the $search_form variable to specify where to print the search form. The page states "$search_form: The complete search form ready for print". But, I get an error ("Undefined variable: search_form") when I try this.
Advice would really be appreciated...Anyone?
_
That page is describing the search-block-form.tpl.php template file-- that's the extent of the existence of the $search_form variable (it's not available by default in the page.tpl.php file).
In d7 the search form is completely block based. So I would think you can either make it available via a preprocess_page function or add a new region to the theme, assign it to that region on the blocks admin page, and print that region out in the page.tpl.php file.
Thanks
This part of your comment: "that's the extent of the existence of the $search_form variable" was enough to put me on the right track. I implemented a very simple search-block-form.tpl.php file that adds the style classes to the rendering of the search block. That's what I needed to accomplish. So, the template simply looks like this:
...and my
page.tpl.php file (the relavent portion of it, anyway) looks like this:
This is giving me the results I want.
Thanks very much for your response.
_
awesome-- thanks for posting back your solution!