Skip to content
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

Relative include paths don't work when using namespaces #433

Open
uandco opened this issue Jun 19, 2023 · 4 comments
Open

Relative include paths don't work when using namespaces #433

uandco opened this issue Jun 19, 2023 · 4 comments

Comments

@uandco
Copy link

uandco commented Jun 19, 2023

Hi,

I'm using a components view namespace by adding this to AppServiceProvider.php:

    public function boot(): void
    {
        view()->addNamespace('components', resource_path('droplets/components'));
    }

This works fine to call views like view('components::forms/input); to load /resources/droplets/components/forms/input.twig but when including other twig templates from input.twig, I need to use an absolute path to point to anything inside /resources/droplets/components.

Using something like {% include 'label' with {label: label} %} will try to load /resources/views/label.twig as twig is not aware the parent template is in the components namespace.

I reckon a way to solve that would be to declare twig path namespaces like you can do in Symphony:
https://symfony.com/doc/current/templates.html#template-namespaces

What is the equivalent to that with TwigBridge, if any?

Thanks!

@uandco
Copy link
Author

uandco commented Jun 20, 2023

Actually I have a workaround by not using namespaces but adding a secondary view path in config/view.php:

    'paths' => [
        resource_path('views'),
        resource_path('droplets/components'),
    ],

But being able to use namespaces in Twig would be nice too to have a finer control on where we want the includes to be loaded from.

@n3storm
Copy link

n3storm commented Jul 13, 2023

Checkout (if you haven't) Laravel Modules package. The project has managed to load and include templates from different modules.

@uandco
Copy link
Author

uandco commented Jul 14, 2023

@n3storm not sure I understand what you mean by "Laravel Modules package".

@n3storm
Copy link

n3storm commented Sep 27, 2023

@n3storm not sure I understand what you mean by "Laravel Modules package".

https://github.com/nWidart/laravel-modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants