-
-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TwigComponent]: allow to configure template naming strategy #2136
Comments
To be sure I understood perfectly your suggestion: are you talking about "template naming", "component naming" or both ? For "template naming", losely based on your example, something like this: # config/packages/twig_component.yaml
twig_component:
defaults:
App\Twig\Components\: components/
App\Twig\Components\Acme:
template_directory: 'components/acme/'
name_prefix: 'Acme'
naming_strategy: 'snake_case' Then this class // src/Twig/Components/Acme/FooBar.php
namespace App\Twig\Components\Acme;
#[AsTwigComponent]
class FooBar
{
// ...
} would be equivalent to #[AsTwigComponent(
template: 'components/acme/foo_bar.html.twig',
]
class FooBar
{ And # Twig syntax
{{ component('Acme:FooBar', { ... }) }}
# will use 'components/acme/foo_bar.html.twig' during render
# HTML syntax
<twig:Acme:FooBar />
# will use 'components/acme/foo_bar.html.twig' during render Or did you imply the entire class Or, to be more precise, any component or template in the <twig:Acme:foo_bar />
# will use 'components/acme/foo_bar.html.twig' during render As you used the |
Yes, only the templates :) your first example is totally right and my expected behavior :-)
|
Yes that's was how i read it, but wanted to be sure.. as if you wanted to change the "name" of the component (not only the template one), it could be something strange to configure component to be named "Acme:foo_bar" :)
Ok, so I'd suggest we call this potential option: Something like this ? # config/packages/twig_component.yaml
# ...
# default: null
template_naming_strategy:
# (equivalent to)
template_naming_strategy: PascalCase
# new option
template_naming_strategy: snake_case What we need to see now is the impact on other things (anonymous, live, etc..) and check for any unwanted side effect. For instance, this will not work for anonymous component (as there is no name to convert), right ? |
You can configure the templates as follows:
which translates to: all Components in the PHP namespace
App\Twig\Components\
will have their templates located in 'components/', soApp\Twig\Components\MyModal
will becomecomponents/MyModal.html.twig
.As some frameworks prefer snake_case over PascalCase, I'd like to configure the naming strategy as follows:
so
App\Twig\Components\MyModal
will becomecomponents/my_modal.html.twig
.The text was updated successfully, but these errors were encountered: