php – 如何在Drupal 8中的搜索结果页面上显示结果数?

我正在尝试在Drupal 8的结果页面显示搜索结果计数,我想显示类似于:search_word的23个结果.

我使用认的Drupal搜索,并使用item-list-search-results.html.twig作为模板文件显示结果,但是我找不到可用变量中的搜索结果计数,任何想法怎么能找到这个值?

解决方法:

Drupal 8中的结果计数没有变量.

1)使用以下代码添加此变量(将此代码添加到MYTHEME.theme):

function MYTHEME_preprocess_item_list(&$variables) {

    $total = null;
  // get the total number of results from the $GLOBALS
  if(isset($GLOBALS['pager_total_items'])){
    $total = $GLOBALS['pager_total_items'][0];
  }

  $variables['count_items'] = $total;
}

2)然后你可以在item-list中使用{{count_items}} – search-results.html.twig:

<div> {{ count_items }} results for search_word </div>

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...