Skip to content

[TwigComponent] Improvements suggestion #108

Closed
@ker0x

Description

@ker0x

First I want to thanks and congratulates @weaverryan and all people involved in making those 2 new components 👏!

I just start a fresh new project, using the Twig Component. and it's already saving me some extra work, this is really appreciate.

Here is a list of some suggestions that could improve this package:

Default path

Add a Bundle configuration parameter default_path, similar to the one for Twig, to define where components are stored.

default_path: '%kernel.project_dir%/templates/components' # default value

Additional paths

Be able to defined multiple Component paths. This can be useful in applications where we want to split each parts:

component_paths: 
 - '%kernel.project_dir%/templates/website/components'
 - '%kernel.project_dir%/templates/admin/components'
 - '%kernel.project_dir%/templates/common/components'

When rendering, it will parse each path to find the component template then fallback to default_path if none is found.

Prefix

It's a common practice to prefix "partial" twig template with _ (e.g. _form_delete.html.twig). Being able to define a "global" prefix without having to specified it in the getComponentName method will be great. The prefix will be concatenate with the component name.

component_prefix: '_' # optional, none by default

Alternate templates

Sometimes, depending on the context, it can be useful to display the component with a different template.

public function getComponentTemplate(): string
{
    return match(this->context) {
        $this->foo() => 'bar',
        $this->bar() => 'foo',
    };
}

Maker command

I'm pretty sure this one is already in the pipe, but having a make:component command to quickly build a component will save some extra work!

WDYT ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions