View namespaces

View namespaces make it possible to have multiple "sets" of certain view file types, such as partials.

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:

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') ?>

Both the $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 $partials->partial_name syntax.

Back to top