【问题标题】:how to edit search area in drupal如何在drupal中编辑搜索区域
【发布时间】:2011-04-04 14:38:25
【问题描述】:

在我的网站 www.rchealth.co.uk,我想添加搜索。

我已启用搜索模块并且搜索块位于标题中,现在我想自定义搜索外观以使其看起来更好。

我搜索了一些方法,比如http://systemseed.com/blog/how-customise-search-box-drupal-6http://drupal.org/node/154137

我按照这些步骤操作,但仍然无法编辑模板。我的drupal版本是6.17

我把这段代码粘贴到了template.php中

function accordlaw_preprocess_search_block_form(&$vars, $hook) {
  // Modify elements of the search form
  unset($vars['form']['search_block_form']['#title']);

  // Set a default value for the search box
  $vars['form']['search_block_form']['#value'] = t('Search RC Health');

  // Add a custom class to the search box
  // Set yourtheme.css > #search-block-form .form-text { color: #888888; }
  $vars['form']['search_block_form']['#attributes'] = array(
     'onblur' => "if (this.value == '') {this.value = '".$vars['form']['search_block_form']['#value']."';} this.style.color = '#000000';",
     'onfocus' => "if (this.value == '".$vars['form']['search_block_form']['#value']."') {this.value = '';} this.style.color = '#000000';"
  );

  // Modify elements of the submit button
  unset($vars['form']['submit']);

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

  // Change submit button into image button - NOTE: '#src' leading '/' automatically added
  $vars['form']['submit']['image_button'] = array('#type' => 'image_button', '#src' => base_path() . path_to_theme() . '/images/search-button.png');

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

  // 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 print entire form
  $vars['search_form'] = implode($vars['search']);
}

【问题讨论】:

  • 您说“无法编辑模板”是什么意思。修改不显示?你在文件中真正添加了什么,发布你的代码。
  • 你想用搜索框做什么?
  • 我想删除文本 搜索此站点:希望使按钮成为图像 减小输入字段的宽度并在搜索区域周围放置背景图像。我还注意到,当我使用管理员登录时,它会在所有页面上显示搜索,但是如果我使用其他浏览器浏览该网站而没有登录,则搜索不会出现。

标签: css drupal templates search


【解决方案1】:

您说搜索块在标题中...您是指主题搜索吗?您正在使用的代码用于 block 搜索表单。

您在未以管理员身份登录时看不到搜索表单的最可能原因是您没有为匿名(可能是经过身份验证的)用户提供正确的“搜索”权限。

要更改主题标题中主题搜索的外观/感觉/功能,您也可以随时使用模板文件 (search-theme-form.tpl.php)。

从 "/modules/search" 复制 search-theme-form.tpl.php 并将其粘贴到您的主题目录中。进行所需的任何编辑,然后在“www.example.com/admin/settings/performance”清除缓存。

更多关于使用search-theme-form.tpl.php的信息:
search-theme-form.tpl.php (Drupal Docs)
How to Theme the Search Form for Drupal 6

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多