簡體   English   中英

Drupal 8 - 如何在 preprocess_views_view 中獲取暴露的過濾器值

[英]Drupal 8 - how to get exposed filters value in preprocess_views_view

我正在使用 preprocess_views_view 來定義一些新變量並將它們傳遞給樹枝模板。

為了定義這些變量,我需要訪問公開的過濾器輸入值,但我似乎無法弄清楚如何:

function my_modules_preprocess_views_view(&$variables) {
  $view = $variables['view'];
  // Here I would need to access the exposed filters value
  $exposed_filter_value = "the_value";
  $variables["foo"] = "Something based on the exposed filters value";
}

我將非常感謝任何線索 - 干杯!

在您的主題或模塊中的hook_preprocess_views_view()實現中:

$values = $view->getExposedInput();
// for example $values["color"];

或者,您可以直接從views-view.html.twig模板訪問這些值:

// Assuming `color` is configured to be the Filter identifier in the 
// view's Filter Criteria exposed filter.
{{ view.getExposedInput.color }}

我在@Hubert 的解決方案中遇到了問題,並設法讓它與:

$variables["searchInputValue"] = $view->exposed_raw_input['query'];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM