我不是世界上最有经验的Drupal,我正在做一个噩梦,试图定制搜索框。我正在使用Drupal帮助站点的示例,它根本不起作用。
我已经将搜索主题-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>发布于 2011-05-20 16:53:26
将预处理函数放在主题目录中的template.php中,然后在“admin/ function /performance”处清除缓存
下面是一些关于模板/预处理函数主题化的有用链接:
https://stackoverflow.com/questions/6074379
复制相似问题