如何在Drupal 8中以树枝形式删除字段?

问题描述 投票:0回答:1

在Drupal 8中,树枝的形状是这样的:

<form{{ attributes }}>
  {{ children }}
</form>

我想显示所有字段,除了第一个。通常,我们使用without过滤器,但是children是字符串,因此无法使用。

<form{{ attributes }}>
  {{ children|without('unwanted') }}
</form>

以小枝的形式,我们可以访问作为数组的element变量。但是,无过滤器在这里仍然无法使用。

<form{{ attributes }}>
 {{ element|without('unwanted') }}
</form>

[我知道我可以用{{ element.field }}来显示所有字段,然后按1逐个显示。但是,如果我的表单有新字段,则在我更新表单树枝之前,将不会打印它们。我想保持动态的目的。

不想想要更新php中的表单代码以使布局保持树枝状。

任何想法?

forms twig drupal-8
1个回答
0
投票

尝试一下:

{% for key in element|keys %}
    {{ children|without(key) }}
{% endfor %}

希望成功...

© www.soinside.com 2019 - 2024. All rights reserved.