Is it possible to combine several template files togather and make single integrated template instead?

For example to render a simple form like search block should be invoked 8 different template like below and each of this template only have one or few line of code, see below:

└─ block.html.twig
   └─ form.html.twig
      ├─ form-element.html.twig
      |  ├─ form-element-label.html.twig
      |  └─ input.html.twig
      └─ container.html.twig
          └─ input.html.twig

As you can see in below some of this files Just have a few line of code:


{% if content %}
  <div{{ attributes }}>
    {{ content }}
{% endif %}


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


{% if title is not empty or required -%}
  <label{{ attributes.addClass(classes) }}>{{ title }}</label>
{%- endif %}

<input{{ attributes }} />{{ children }}

<div{{ attributes.addClass(classes) }}>{{ children }}</div>

  • Some of this templates files are common with other part of page and editing each of them can affect to other parts and cause unwanted changes.
  • Editing and managing this template files is tedious and difficult and make my theme folder busy.
  • Most of these templates have ambiguity and unclear content code.

For this reason I’m looking for a method to combine this template files and make one template file like “form--search-block.html.twig” to I can edit all element needs for rendering a form in one special place and with more flexibility and confidently.

Drupal version: