PHPackages                             wp-strap/view - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. wp-strap/view

AbandonedLibrary[Templating &amp; Views](/categories/templating)

wp-strap/view
=============

PSR Template loader to use in WordPress plugins.

0.1.1(2y ago)031BSD-2-ClausePHP

Since Jul 6Pushed 2y ago1 watchersCompare

[ Source](https://github.com/wp-strap/view)[ Packagist](https://packagist.org/packages/wp-strap/view)[ RSS](/packages/wp-strap-view/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (8)Versions (3)Used By (0)

Usages
------

[](#usages)

Install dependency into your project.

```
composer require wp-strap/view

```

This exposes some classes which are responsible loading template files inside plugins (but can also be used for themes).

The classes follow PSR practices with interfaces, so it can be included trough OOP with dependency injection and IoC containers. It also provides a Facade class that allows you to use static methods instead to call the methods everywhere you like.

Example with using the facade:

```
use WPStrap\View\View;

// Resolves instance and registers project configurations
View::register([
    'dir' => plugin_dir_path(__FILE__), // or get_stylesheet_directory() for themes
]);

echo View::render('my-component')->args([
    'my-argument' => 'my-value'
])
```

Example with using the instance

```
use WPStrap\View\View;
use WPStrap\View\ViewService;

// Instantiates the Asset service and registers project configurations
$views = new ViewService();

$views->register([
    'dir' => plugin_dir_path(__FILE__), // or get_stylesheet_directory() for themes
]);

// Renders template with arguments
echo $views->render('my-component')->args([
    'my-argument' => 'my-value'
])

// You can also use the facade based on this instance.
View::setFacade($views);
View::render('my-second-component');
```

Example with using instance as function

```
use WPStrap\View\ViewInterface;
use WPStrap\View\ViewService;

function views(): ViewsInterface {
     static $views;

     if(!isset($views)) {
        $views = (new ViewService())->register([
            'dir' => plugin_dir_path(__FILE__),
        ]);
     }

     return $views;
}

echo views()->render('my-component')->args([
    'my-argument' => 'my-value'
])
```

Example with using the League Container

```
use League\Container\Container;
use WPStrap\View\View;
use WPStrap\View\ViewInterface;
use WPStrap\View\ViewService;

$container = new Container();
$container->add(ViewsInterface::class)->setConcrete(ViewService::class)->addMethodCall('register', [
    'dir' => plugin_dir_path(__FILE__),
]);

$views = $container->get(ViewsInterface::class);

echo $views->render('my-component')->args([
    'my-argument' => 'my-value'
])

// You can also set a PSR container as facade accessor
View::setFacadeAccessor($container);
View::render('my-second-component');
```

### Base settings

[](#base-settings)

It locates the template files from the "views" folder by default (eg: `your-plugin-folder/views` ).

```
$views->register([
    // Determines the root dir of your project
    'dir' => plugin_dir_path(__FILE__),

    // Will change templates path to "your-plugin-folder/path-to-views/views"
    'path' => 'path-to-views',

    // Changes "your-plugin-folder/views" to "your-plugin-folder/templates"
    'folder' => 'templates',

    // Will override templates from theme/child-themes if templates exist in the
    // "clients-theme/my-plugin-name" directory, this is turned off by default
    // to remove the performance load since it won't be needed for most plugins
    'locate' => 'my-plugin-name',

    // By default it uses the plugin folder name as hook prefix for filters inside the
    // classes (eg: a filter for "my-plugin-folder" becomes "my_plugin_folder_view_args")
    // With this setting you can change the prefix
    'hook' => 'my_plugin_hook',
]);
```

### Domain folder

[](#domain-folder)

If you have a domain folder structure like this

```
my-custom-plugin/
├── src/
│   ├── Blocks/
│   │    └── Static/
│   │         ├── css/
│   │         ├── js/
│   │         ├── views/
│   │         │    ├── example-block.php
│   │         │    └── another-example-block.php
│   │         └── images/
│   ├── Admin/
│   │    ├── Admin.php
│   │    └── Static/
│   │         ├── css/
│   │         ├── js/
│   │         ├── views/
│   │         │    ├── admin-page.php
│   │         │    └── another-admin-page.php
│   │         └── images/
│   ├── Main/
│   │    ├── Main.php
│   │    └── Static/
│   │         ├── css/
│   │         ├── js/
│   │         └── images/

```

You can use the first param of the render() method to point to the domain folder

```
$views->register([
    'dir' => plugin_dir_path(__FILE__),
    'path' => 'src'
 ]);

echo $views->render('Blocks', 'my-example-block')->args([
    'my-argument' => 'my-value'
]);
```

If you use another name for "Static" you can use the "entry" setting to change it to something else

```
$views->register([
    'dir' => plugin_dir_path(__FILE__),
    'path' => 'src',
    'entry' => 'templates'
 ]);
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1046d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/52fd7691abe58e8577c01e05a75959907449859d095fe3a6f36d516d7e599dfe?d=identicon)[WP-Strap](/maintainers/WP-Strap)

### Embed Badge

![Health badge](/badges/wp-strap-view/health.svg)

```
[![Health](https://phpackages.com/badges/wp-strap-view/health.svg)](https://phpackages.com/packages/wp-strap-view)
```

###  Alternatives

[moonshine/moonshine

Laravel administration panel

1.3k217.1k59](/packages/moonshine-moonshine)[laminas/laminas-view

Fast and type safe HTML templating library with a flexible plugin system supporting multistep template composition

7526.3M230](/packages/laminas-laminas-view)[qossmic/rich-model-forms-bundle

Provides additional data mapper options that ease the use of the Symfony Form component with rich models.

218278.7k](/packages/qossmic-rich-model-forms-bundle)[rareloop/lumberjack-core

A powerful MVC framework for the modern WordPress developer. Write better, more expressive and easier to maintain code

42155.0k19](/packages/rareloop-lumberjack-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
