Reputation: 2200
I want to output the built in Drupal "search" block inside of my "primary links" menu, which is built by the theme function framework_primary_links() inside template.php. The menu should end up looking like the StackOverflow menu: [chat | meta | about | faq | __search__], so the "search" field is inside the menu <ul> itself.
So I'm not just printing the search block inside a region like normal.
Currently I'm doing:
$search_block = (object) module_invoke('search', 'block', 'view', 0);
$output .= '<li id="searchContainer">' . theme('block', $search_block) . '</li>';
But Drupal is applying the "block.tpl.php" template and not the "block-search.tpl.php" template like I want it to.
How do I get Drupal to apply the "block-search.tpl.php" template file to my programmatically rendered block?
Upvotes: 1
Views: 1053
Reputation: 2200
I found one solution — manually set the "module" and "delta" on the block object:
$search_block = (object) module_invoke('search', 'block', 'view', 0);
$search_block->module = 'search';
$search_block->delta = 0;
$output .= '<li id="searchContainer">' . theme('block', $search_block) . '</li>';
Upvotes: 0
Reputation: 2052
Doing drupal_get_form('search_block_form')
will return the markup for the core Search form, and it'll have already gone through the search block form template so you could change your code to:
<?php
$output .= '<li id="searchContainer">' . drupal_get_form('search_block_form') . '</li>';
Upvotes: 2