首页 > 解决方案 > 如何访问 views-exposed-form.html.twig 中的表单字段(暴露的过滤器)

问题描述

我正在尝试为视图的公开过滤器自定义模板。

我已经创建了views-exposed-form.html.twigDrupal 并且可以很好地加载它。现在,我有标准代码:

{#
/**
 * @file
 * Theme override of a views exposed form.
 *
 * Available variables:
 * - form: A render element representing the form.
 *
 * @see template_preprocess_views_exposed_form()
 */
#}
{% if q is not empty %}
  {#
    This ensures that, if clean URLs are off, the 'q' is added first,
    as a hidden form element, so that it shows up first in the POST URL.
  #}
{{ q }}
{% endif %}
{{ form }}

这很好用。然而,如果我尝试只显示表单的一个字段(例如,twig {{ form.field_city }}),则过滤器块中不会显示任何内容,尽管页面加载正常并且没有明显的错误。

我正在使用 Drupal 8.7.7 和 PHP 7.3.9。

任何帮助都将受到欢迎。

先感谢您。

标签: twigdrupal-8

解决方案


问题似乎是与 Better Exposed Filters 模块不兼容。


推荐阅读