Skip to content

9. Namespaced views

Giannis Gasteratos edited this page Jun 27, 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:

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

Custom Namespaces

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

A short example:

Suppose that you have defined the following namespace:

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

Your themes will add the same path inside the theme folder in the lookup array. So if you render view('my-namespace::view-name') then these files will be retrieved with the following order:

  1. Theme_Path\resources\namespace\view-name\.blade.php
  2. resources\namespace\view-name.blade.php