TwigBridge icon indicating copy to clipboard operation
TwigBridge copied to clipboard

$loader->addPath

Open sil2 opened this issue 8 years ago • 1 comments

Is there a way to "add path" into twig like $loader->addPath?

I have layouts folder on the same level as my templates folder and I want to use extends in my template to one of the layouts.

sil2 avatar Apr 09 '16 17:04 sil2

You may register a FilesystemLoader, rebind the twig.loader to add the new loader to the chain of loaders, with your paths and namespaces:

app()->bind('twig.loader.filesystem', function () {
    $loader = new FilesystemLoader(
        [resource_path('twig-templates')],
        base_path()
    );

    $loader->addPath(
        resource_path('twig-templates/components'),
        'components'
    );

    return $loader;
});

app()->bind('twig.loader', function () {
    return new ChainLoader([
        app('twig.loader.array'),
        app('twig.loader.viewfinder'),
        app('twig.loader.filesystem'),
    ]);
});

AppServiceProvider is a nice place to register this.

antonioribeiro avatar Nov 07 '19 02:11 antonioribeiro