在 Drupal 中设置搜索框主题时遇到问题
我不是世界上最有经验的 Drupal,并且在尝试自定义搜索框时我遇到了一场噩梦。我正在使用 Drupal 帮助站点上的示例,但它根本不起作用。
我已将 search-theme-form.tpl.php 从搜索模块复制到我的主题中,并复制了示例代码,该代码中预处理函数之外的任何 HTML 都显示正常,但据我所知,预处理-process 函数要么没有被调用,要么只是不影响我的搜索框。
我几乎可以肯定我错过了一些关于 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>
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 shows 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将预处理函数放入主题目录中的
template.php
中,然后清除“admin/settings/performance”中的缓存以下是一些有用的链接,可帮助您了解如何使用模板/预处理函数进行主题化:
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: