Drupal 8 - 如何在 preprocess_views_view 中获取暴露的过滤器值
Drupal 8 - how to get exposed filters value in preprocess_views_view
我正在使用 preprocess_views_view 定义一些新变量并将它们传递给 twig 模板。
为了定义这些变量,我需要访问暴露的过滤器输入值,但我似乎无法弄清楚如何:
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'];
我正在使用 preprocess_views_view 定义一些新变量并将它们传递给 twig 模板。
为了定义这些变量,我需要访问暴露的过滤器输入值,但我似乎无法弄清楚如何:
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'];