This is a follow-up issue to #1842160: Consider appropriate usage of theme() from within Twig templates We now just need to go cleanup our template files that included others, and remove the @todos.
Usage of {% include %} or theme() in templates represents some sort of recursion or sub-structure that is part of a template. Instead of using include directives or theme(), we should attempt to do the following in these instances:
* (A) Address sub-structure in the parent template to avoid both includes and theme(). A good example of this is where we'd have separate theme functions for table cells vs tables. Table cells are never independent of tables, so they should be consolidated to one template (i.e. renderable concept).
* (B) Have sub-structure be renderable, that is, an {{ item }} knows how to render itself, analogous to how render($var); was intended to operate
* (C) Pre-render markup in preprocessors. If theme() must be called, have it run in a preprocessor. @todo Is this an anti-pattern? Probably. We should avoid using theme() since it can invoke the theme layer too early, and use renderable arrays instead.
Comments
Comment #1
c4rl commentedGiven the change in direction of #1842160: Consider appropriate usage of theme() from within Twig templates, I'm updating the summary to reflect that we want to either (A) address sub-structure in the parent template to avoid both includes and theme(), (B) have sub-structure be renderable, or (C) pre-render markup in preprocessors.
Comment #1.0
c4rl commentedUpdated issue summary to reflect new direction
Comment #2
joelpittet(B) would be my preference, but how do we make those items renderable?
Comment #3
c4rl commentedWe may have to resort to (A) and (C) for now until we can address render shortcomings elsewhere -- I've already peered into pandora's box here :) #1899454: [meta] Refactor Render API
Comment #4
steveoliver commentedAt the moment we're doing (C) in #1778624: rework theme_filter_tips to use the new Attributes, and call theme('item_list) while we're at it.
If you wanted to theme filter guidelines (the list of tips below a textarea when there are text filter options), the Twig workflow would be:
filter-guildelines.html.twig:- has attributes, titles and other vars preprocessed and ready for print.
- has a {{ tips }} variable which is a preprocessed
<ul>item list which can be overridden initem-list--filter-tips-guidelines.html.twigNot ideal, but I think it works for now.
Comment #5
c4rl commentedI think for the sake of getting things done, we have to stick with (C) for now, then (in core) attempt to refactor as (A), and eventually figure out (B).
So, to this end, it seems all of these files listed below need to have the
{% include %}directive removed. I will attempt to make progress here ASAP, committing to front-end branch. Let me know if there are any objections.Comment #6
c4rl commentedSince #1812724: Consolidate all form element templates and add theme_hook_suggestons is fixed, I've removed the following:
Comment #7
c4rl commentedI've made the following identical to core/themes/stark/templates/form.inc/container.html.twig until #1819284: [meta] Consolidate all form element container templates, and add theme_hook_suggestions is resolved.
Comment #8
c4rl commentedMarking this as fixed now. All calls to include are now removed.
Comment #9.0
(not verified) commentedformatting