Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
We have many template files that start with logic that, if fails, will prevent anything from being printed at all. It would be smarter if we could prevent these template files from being rendered at all when not necessary.
For example, theme_comment_post_forbidden turns into the following twig file:
{% if logged_out and can_post_comments %}
{% if user_register %}
{% set args = {'@login': user_login_url, '@register': user_register_url} %}
{{ '<a href="@login">Log in</a> or <a href="@register">register</a> to post comments' | t(args) }}
{% else %}
{% set args = {'@login': user_login_url} %}
{{ '<a href="@login">Log in</a> to post comments' | t(args) }}
{% endif %}
{% endif %}
Proposed resolution
We should think about whether we should find a way to allow Twig/the theme system to skip the rendering of a template when these conditions are not met.
Some possible candidates:
(Click View source to see the template code)
- admin-block-content.html.twig
- book-navigation.html.twig
- breadcrumb.html.twig
- dropbutton-wrapper.html.twig
- forums.html.twig
- item-list.html.twig
- links.html.twig
- pager.html.twig
- region.html.twig
- views-mini-pager.html.twig
Remaining tasks
TBD
User interface changes
none.
API changes
TBD
Related Issues
#1706612: remove 'submitted' variable in templates for ease of theme development
Comments
Comment #0.0
jenlamptonmore words
Comment #1
joelpittetThis sounds like it may be something to consider with '#access' => FALSE on a renderable array?
Comment #2
star-szrI think we should also keep in mind the "API" of the theme system and what developers expect when using themeable components. For example, do module developers/theme developers expect things to be handled for them or that they might have to handle some logic up front? I think right now we have a mixture, it's not consistent.
I did a quick search and added some candidates to the issue summary.