在Drupal中搜索框出现问题
问题描述:
我不是世界上经验最丰富的Drupal,我有一个恶梦试图自定义搜索框。我使用Drupal帮助网站的示例,它根本无法工作。在Drupal中搜索框出现问题
我已将search-theme-form.tpl.php从搜索模块复制到我的主题中并复制了示例代码,该代码中的任何HTML都在预处理函数之外显示出良好但尽可能我可以告诉,预处理功能要么不被调用,要么不影响我的搜索框。
我几乎可以肯定,我错过了一些关于Drupal如何工作的绝对基本的基础知识,但是我根本找不到任何信息。
下面的代码:
<?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>
答
把预处理功能template.php
在你的主题目录,然后清除缓存在“管理/设置/业绩”
下面是一些有用的链接了解主题化与模板/预处理功能: