Accessing a Twig Component in a bundle #2648
Replies: 4 comments 1 reply
-
Could you show us the result of |
Beta Was this translation helpful? Give feedback.
-
Could you also show us the config for twig component? https://symfony.com/bundles/ux-twig-component/current/index.html#configuration # config/packages/twig_component.yaml
twig_component:
defaults:
# short form: components under this namespace:
# - name will be the class name that comes after the prefix
# App\Twig\Components\Alert => Alert
# App\Twig\Components\Button\Primary => Button:Primary
# - templates will live in "components/"
# Alert => templates/components/Alert.html.twig
# Button:Primary => templates/components/Button/Primary.html.twig
App\Twig\Components\: components/ You might need to prepend you namespace and components/ template path for your bundle if it's not already the case |
Beta Was this translation helpful? Give feedback.
-
Eh, my bad. |
Beta Was this translation helpful? Give feedback.
-
When in a bundles, it's best to be explicit about the name. <twig:SurvosFw:Framework7Page
:caller="_self"
:showBackButton="true"
>
<twig:block name="content">
This is in {{ _self }}, and is specific to about.
</twig:block>
</twig:SurvosFw:Framework7Page> <?php
namespace Survos\FwBundle\Components;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
use Symfony\UX\TwigComponent\Attribute\PreMount;
#[AsTwigComponent('SurvosFw:Framework7Page', template: '@SurvosFw/components/FwPage.html.twig')]
final class FwPage
{
public string $caller;
public ?string $name=null;
public ?string $title=null; |
Beta Was this translation helpful? Give feedback.
-
I'm not seeing the PHP Twig Component, only the templates. So my call to the component that's in the bundle is failing.
I'm registering in the bundle config file
And I can see the templates.
Does the component need a 'twig.component' tag or something (I tried that, but it didn't work).
This works when I had the same code in the app, but not in the bundle. Is there something special I need to do for twig namespaces to register them in the bundle?
Beta Was this translation helpful? Give feedback.
All reactions