简体   繁体   English

Drupal 9 搜索表单中没有结果消息

[英]Drupal 9 No result message in search form

I added 'No result behavior' in the view and it shows up right away.我在视图中添加了“无结果行为”,它立即显示出来。 How can I make this message appear only after clicking on the Submit button and if there are no search results?只有在单击“提交”按钮并且没有搜索结果的情况下,如何才能使此消息出现? Drupal 9.3, Using the Search API. Drupal 9.3,使用搜索 API。

I need to display this message if there are no search results.如果没有搜索结果,我需要显示此消息。 Maybe there is a better way than using 'No result behavior'?也许有比使用“无结果行为”更好的方法?

在此处输入图像描述

在此处输入图像描述

By default when you open view page drupal show a "first search", if you already don't have any result on this view drupal shows "no result" message you have defined.默认情况下,当您打开视图页面 drupal 时会显示“第一次搜索”,如果您在此视图上还没有任何结果 drupal 会显示您定义的“无结果”消息。

For example, on a view listing all News on your website, if user search for a keyword doesn't exist drupal will shows "no result" message.例如,在列出您网站上所有新闻的视图中,如果用户搜索关键字不存在 drupal 将显示“无结果”消息。

It is not logical show an empty page when an user access it, because the user won't search anything if you don't have anything to show on that view, that's why drupal shows "no result" message when you open the page.当用户访问它时显示一个空页面是不合逻辑的,因为如果您在该视图上没有任何内容可显示,用户将不会搜索任何内容,这就是 drupal 在您打开页面时显示“无结果”消息的原因。

I added a text area in 'No result behavior' and just delete it when necessary in hook_preprocess_views_view__VIEWID:我在“无结果行为”中添加了一个文本区域,并在必要时在 hook_preprocess_views_view__VIEWID 中将其删除:

if (empty($variables['rows']) && empty($_GET['search_api_fulltext'])) {
  unset($variables['empty']['area']);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM