Template is not defined error on admin pages when using administration theme

Created on 22 January 2020, over 4 years ago
Updated 31 May 2024, 29 days ago

Problem

Components! fails to discover templates from the primary theme when "use admin theme" is enabled and admin theme is active.
For example, when editing a view that displays rendered content.

Proposed Resolution

During namespace resolution and template discovery, include both the admin theme and primary theme.

Remaining tasks

  • Change record (is this necessary for beta releases?)

User interface changes

none

API changes

ConfigFactoryInterface argument added to Drupal\components\Template\ComponentsRegistry constructor and service definition.

Data model changes

none

Symptom

Fatal errors like
Twig\Error\LoaderError: Template "@organisms/header-top/header-top.twig" is not defined in "themes/custom/aedt_theme/src/templates/layout/region--header-top.html.twig" at line 9. in Twig\Loader\ChainLoader->getCacheKey() (line 142 of vendor/twig/twig/src/Loader/ChainLoader.php).

Steps to reproduce

  • Define a component namespace in your theme
  • Create a page template that embeds another component using that namespace
  • Login as a user with permission to view the admin theme (but not user 1)
  • Setup a custom 403 page
  • Edit a node you don't have permission to edit

Expected behavior

View the 403 page.

Observed behavior

Fatal error described above.

This issue persists even after the component definition has been updated with the 3.x API changes.

Here's an example component library definition:

components:
  namespaces:
    organisms:
        - src/_patterns/03-organisms

And this is how the region--header-top.html.twig file looks like:

{% if content %}
  {% include '@organisms/header-top/header-top.twig' with {
    'content': content,
    'attributes': attributes
  } %}
{% endif %}
๐Ÿ› Bug report
Status

Needs work

Version

3.0

Component

Code

Created by

๐Ÿ‡ง๐Ÿ‡ชBelgium inge_dt

Live updates comments and jobs are added and updated live.
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.

Production build 0.69.0 2024