I have a search block enabled at top side of my site. But I also need to display the same search form, but with different css class applied inside a node. How this can be done?


Since blocks can only go in a single region (without some messing about), I think you'll have to use code for this. You could add the form in a preprocess function in your theme's template.php file:

function MYTHEME_preprocess_node(&$vars) {
  if ($vars['node']->type == 'my_node_type') {
    $form = drupal_get_form('search_form');

    $vars['search_form'] = render($form);

Now in your node.tpl.php file, or node--content_type.tpl.php file, you'll be able to output the search form like this:

<?php if ($search_form): echo $search_form; endif; ?>

The default classes and ID added to the <div> surrounding the node will be be perfect for targeting that particular instance of the form with CSS. You can easily use developer tools/firebug to determine what selector to use.

| improve this answer | |
  • But I have already changed display of search block using function MYTHEME_form_alter(&$form, &$form_state, $form_id) . So now i want another set of parameters for search form only for particular node – user7282 May 28 '12 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.