TwigBridge
TwigBridge copied to clipboard
$loader->addPath
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.
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.