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:
region.html.twig
└─ 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:
region.html.twig
{% if content %}
<div{{ attributes }}>
{{ content }}
</div>
{% endif %}
form.html.twig
<form{{ attributes }}>
{{ children }}
</form>
form-element.html.twig
{% if title is not empty or required -%}
<label{{ attributes.addClass(classes) }}>{{ title }}</label>
{%- endif %}
input.html.twig
<input{{ attributes }} />{{ children }}
container.html.twig
<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.
Comments
The answer is no.
The answer is no.
EDIT, I should elucidate - technically it's plausible, yes, but in reality I think you'll run into big problems and technical challenges. I think you're looking for an easy way to do this sort of thing, but it won't be easy, in fact you're going to make your life hell.
So lets address things we can do something about:
Use template suggestions.
In time you will learn what each one does etc. Nothing, and I mean zero, is added to Drupal core without solid use cases and there being strong reasons for doing so.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Thanks for your help and
Thanks for your help and attention, but in this case drupal theme system hasn't any good template suggestion for example for: "input.html.twig", drupal core suggest only "input--submit.html.twig" and this suggestion also common between "search block" and "search form".
Then create you own template
Then create you own template suggestions.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
how can i create myown
how can i create myown suggestion for "input.html.twig", drupal core only suggest "input--submit.html.twig" in debugging mode. can you give me better suggestion?