开发者

Having problems theming the search box in Drupal

I'm not the world's most experienced Drupal and I'm having a nightmare trying to customise the search box. I'm using the example from the Drupal help site and it's simply not working.

I've copied search-theme-form.tpl.php from the search module into my theme and copied the example code, Any HTML in that code outside of the pre-process function sh开发者_开发百科ows fine but as far as I can tell, the pre-process function either isn't called or just isn't affecting my search box.

I'm almost certain that I'm missing something absolutely fundamentally basic about how Drupal works but I can't find any info at all.

Here's the code:

 <?php 

function danland_preprocess_search_theme_form(&$vars, $hook) {
      // Remove the "Search this site" label from the form.


  $vars['form']['search_theme_form']['#title'] = t('');

  // Set a default value for text inside the search box field.
  $vars['form']['search_theme_form']['#value'] = t('Search this Site');

  // Add a custom class and placeholder text to the search box.
  $vars['form']['search_theme_form']['#attributes'] = array('class' => 'NormalTextBox txtSearch', 'onblur' => "if (this.value == '') {this.value = '".$vars['form']['search_theme_form']['#value']."';} ;", 'onfocus' => "if (this.value == '".$vars['form']['search_theme_form']['#value']."') {this.value = '';} ;" );


  // Change the text on the submit button
  //$vars['form']['submit']['#value'] = t('Go');

  // Rebuild the rendered version (search form only, rest remains unchanged)
  unset($vars['form']['search_theme_form']['#printed']);
  $vars['search']['search_theme_form'] = drupal_render($vars['form']['search_theme_form']);

  $vars['form']['submit']['#type'] = 'image_button';
  $vars['form']['submit']['#src'] = path_to_theme() . '/images/search.jpg';

  // Rebuild the rendered version (submit button, rest remains unchanged)
  unset($vars['form']['submit']['#printed']);
  $vars['search']['submit'] = drupal_render($vars['form']['submit']);

  // Collect all form elements to make it easier to print the whole form.
  $vars['search_form'] = implode($vars['search']);
}

?>


<div id="search" class="container-inline">
  <?php print $search_form; print $search_theme_form; ?>
</div>


Put the preprocess function in template.php in your theme directory, then clear the cache at "admin/settings/performance"

Here are some helpful links to learn about theming with templates/preprocess functions:

  • About overriding themable output
  • Setting up variables for use in a template (preprocess and process functions)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜