Skip to content

Improvement suggestion: simplify component template management #1029

@asispts

Description

@asispts

In the current implementation, the class for a Twig component is stored in /src/ directory, while its template is placed in /templates/components/. This approach can become burdensome to manage the components.

./
├─ src/
│  ├─ TwigComponent/
│  │  ├─ AComponent.php
├─ templates/
│  ├─ components/
│  │  ├─ AComponent.html.twig

A simpler and clearer alternative is to keep the component template next to its class. For instance, in the class component definition:

#[AsTwigComponent(tpl: __DIR__.'/AComponent.html.twig')]
class AComponent{}

With this approach, the directory structure would look like:

./
├─ src/
│  ├─ TwigComponent/
│  │  ├─ AComponent.php
│  │  ├─ AComponent.html.twig

Alternatively, you could use a separate folder named _tpl for templates:

#[AsTwigComponent(tpl: __DIR__.'/_tpl/AComponent.html.twig')]
class AComponent{}

With this setup, the directory structure would be:

./
├─ src/
│  ├─ TwigComponent/
│  │  ├─ _tpl/
│  │  │  ├─ AComponent.html.twig
│  │  ├─ AComponent.php

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions