我不是世界上最有经验的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>
答案 0 :(得分:0)
将预处理功能放在主题目录的template.php
中,然后在“admin / settings / performance”清除缓存
以下是一些有用的链接,用于了解模板/预处理功能的主题: