I am trying to theme a form in Drupal 8.

This is the template that I am using which is basically from form.html.twig

<form{{ attributes }}>
{{ element.app_theme_settings }}
{{ element.a2 }}
{{ element.a3 }}

 {% print remaining required form fields. %}
 {{ children }}

My problem is I want to print children variable but without app_theme_settings, a2 and a3 children. In Drupal 7 we could use unset function, but in twig I am not sure what to use. I know I can use without filter, but it does not accept the array argument so I have to write name of each element already printed.

 {{ children|without('app_theme_settings','a2','a3' }}

How can I print children without specifying the name of each field one by one?


Loop through the keys

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.