View namespaces is a feature that makes it possible to configure one or more namespaces, specify a root folder for each, and then use these to render view files from. Potential use cases for view namespaces:
- One or more "custom" directories containing partials of a specific type, such as the "sublayout" files used as an example on this docs page.
- Grouping files by type and avoiding any name collisions, regardless of partial file directory structure.
- Bundling partials in a module and calling them directly from the module's directory.
View namespace support was added in Wireframe 0.23.0.
Configuring view namespaces
View namespaces can be configured via the
$config->wireframe array. Here's a simple example:
$config->wireframe = [ 'view_namespaces' => [ 'sublayouts' => $config->paths->templates . 'sublayouts/', ], ];
Another, more generic example would be opening your entire templates directory to be used as partials:
$config->wireframe = [ 'view_namespaces' => [ 'templates' => $config->paths->templates, ], ];
Note that (at least for now) you cannot use paths outside the "site" directory, as that could have potential security implications.
Rendering namespaced partials
With the above "sublayouts" example config in place, and a file called "basic.php" in your /site/templates/sublayouts/ directory, here's how you could render it:
<?= $partials->render('sublayouts::basic') ?>
$partials->get() method and the static
Wireframe::partial() method also support namespaces. In fact only place where namespaces are not supported (for quite obvious reasons...) is the object-oriented