Remove current path parts from theme suggestions

Created on 28 May 2014, about 11 years ago
Updated 18 July 2025, 1 day ago

#788900: Deprecate and remove usages of arg() β†’ reminded me that we still generate theme and template suggestions based on path, for example page--node--1.tpl.php

The problem

Now that most code in core is based on routes, someone could change /node/% to /content/% and your theme would break. This makes those suggestions impossible to use in contrib themes since they can't work generically.

Additionally HTML head is one of the least-cacheable parts of the page in 8.x, and per-path suggestions will make it harder to cache that HTML.

Also these suggestions are a bit broken in D8 in the first place, they include a suggestion with a percent character:

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'html' -->
<!-- FILE NAME SUGGESTIONS:
   * html--node--2.html.twig
   * html--node--%.html.twig
   * html--node.html.twig
   x html.html.twig
-->
<!-- THEME DEBUG -->
<!-- THEME HOOK: 'page' -->
<!-- FILE NAME SUGGESTIONS:
   * page--node--2.html.twig
   * page--node--%.html.twig
   * page--node.html.twig
   x page.html.twig
-->

Proposed solution

Remove the automatic theme suggestions based on path parts.

Why this should be an RC target

1. This is code removal only.

2. In general, contrib themes never use the per-page suggestions (and if they do they're fragile), they're sometimes used by custom themes (and often incorrectly when block configuration, page manager or similar would be a better choice). So the disruption in terms of number of themes using the feature should be low.

3. New theme developers sometimes use this 'by mistake' instead of the better options in #2, which can lead to custom themes with 10-15 page templates all with minro variations, this is one of the worst maintenance issues with custom themes in the wild.

4. Also themes can add back the suggestions by copying the removed code to template.php.

5. While templates using the suggestions won't be picked up, there's no other disruption to actual sites from the change in terms of errors etc. even if they're using the feature, which 99.9% won't be.

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

theme system

Created by

πŸ‡¬πŸ‡§United Kingdom catch

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

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

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    Lets keep this for now.

    We're close to add support for theme hook suggestions. That said, not sure this is worth the trouble. This is discouraged but there are going to be so, so many such templates out there

Production build 0.71.5 2024