Problem/Motivation

If a developer organizes their component system's templates with sub-directories, it is required to use the sub-directory path when referencing the template.

For example, if a theme configure the @components namespace to point at THEME/components and places a box.twig template in THEME/components/containers/box/box.twig, then a developer would be required to use the following syntax to include that template:

{{ include("@components/containers/box/box.twig", ...) }}

However, component system designers never re-use component names, so there is not going to be two different templates named the same; e.g. only one box.html.twig file will exist in the system.

So while, organizing templates in sub-directories makes sense, having to use the sub-directory path every time you want to use that component template is annoying and not necessary to differentiate between components.

Proposed resolution

Make it possible for developers to only have to use the namespace and the template name when referencing a component's template.

{# Syntax required with Components 8.x-2.x: #}
{{ include("@components/containers/box/box.twig", ...) }}

{# Proposed syntax with Components 3.x #}
{{ include("@components/box.twig", ...) }}

Remaining tasks

On-the-fly searching through multiple directories to find the correct template is going to be a performance hit, so we need to introduce a cache that stores all the paths to template files.

API changes

Both the old syntax (with directory path) and the new syntax would work for Twig's include, embeds and extends.

Issue fork components-3191392

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

JohnAlbin created an issue. See original summary.

johnalbin’s picture

Assigned: Unassigned » johnalbin
Status: Active » Needs review

  • JohnAlbin committed 1d344c2 on 3.x
    Issue #3191392 by JohnAlbin: Make subdirectory path optional when using...
johnalbin’s picture

Assigned: johnalbin » Unassigned
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.