Skip to content

9. Namespaced views

Giannis Gasteratos edited this page Nov 19, 2017 · 4 revisions

Laravel allows views to be grouped under a namespace. Each namespace defines one or more paths, where the views will be looked-up. This feature is used mainly in packages to organize package-specific views.

Overiding Package Views:

Packages will look up for view files into the vendor folder of the active theme. If there are parent Themes defined then it will search inside the whole theme hierarcy, and in the end it will fallback to default namespace paths...

view('VENDOR_NAME::viewName'); //  \Theme_Path\VENDOR_NAME\viewName.blade.php

Create Custom Namespaces

Each Theme will remap namespace-defined paths inside the active theme folder.

A short example:

Suppose that you have defined the following namespace:

view()->addNamespace('my-namespace', [
    base_path('resources/namespace'),
]);

Your themes will search for views into same path inside the theme folder. So if you render view('my-namespace::view-name') it will be looked-up into Theme_Path\resources\namespace\view-name.blade.php (and it's parent themes if defined) and then fallback to the resources\namespace\view-name.blade.php