Add is_front variable in html.html.twig template

Created on 24 July 2024, 4 months ago
Updated 25 July 2024, 4 months ago

Problem/Motivation

You may want to check if the frontpage is being displayed in html.html.twig, to alter for example the <title> tag content.

If you try to use is_front variable, nothing will happen, since the variable is not available. It is only available in page.html.twig:

$ grep -liR "is_front" ./core | grep twig
./core/themes/stable9/templates/layout/page.html.twig
./core/themes/starterkit_theme/templates/layout/page.html.twig
./core/themes/olivero/templates/layout/page.html.twig
./core/themes/claro/templates/page.html.twig
./core/profiles/demo_umami/themes/umami/templates/layout/page.html.twig
./core/modules/system/templates/page.html.twig

PS: I found out later that altering the <title> tag content is most easily done with the Metatag โ†’ module.

Steps to reproduce

Try to use is_front variable in the html.html.twig template and fail.

Proposed resolution

Add is_front variable in the html.html.twig template.

A temporary work around is to instead check if the root_path is empty:

{% if root_path is empty %}
  This is front
{% endif %}

Taking a helicopter perspective: Would it be possible to streamline template files, to have more uniform variables sections? The available variables seem to overlap, or only be present in one (html.html.twig), and not the other(page.html.twig). Maybe they could look more like each other?

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

โœจ Feature request
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Themeย  โ†’

Last updated about 19 hours ago

Created by

๐Ÿ‡ฉ๐Ÿ‡ฐDenmark ressa Copenhagen

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024