在 Drupal 中设置搜索框主题时遇到问题

发布于 2024-11-09 06:12:17 字数 1927 浏览 2 评论 0原文

我不是世界上最有经验的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北斗星光 2024-11-16 06:12:17

将预处理函数放入主题目录中的 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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文