PHPackages                             morningtrain/wp-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. morningtrain/wp-view

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

morningtrain/wp-view
====================

Laravel views and blade for WordPress

v0.4.3(3y ago)22.2k11MITPHP

Since Oct 22Pushed 3y ago4 watchersCompare

[ Source](https://github.com/Morning-Train/wp-view)[ Packagist](https://packagist.org/packages/morningtrain/wp-view)[ RSS](/packages/morningtrain-wp-view/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (2)Versions (16)Used By (1)

Views
=====

[](#views)

Laravel blade and view for WordPress with custom directives.

Table of Contents
-----------------

[](#table-of-contents)

- [Introduction](#introduction)
- [Getting Started](#getting-started)
    - [Installation](#installation)
- [Dependencies](#dependencies)
    - [illuminate/view](https://github.com/illuminate/view)
    - [morningtrain/php-loader](#morningtrainphp-loader)
- [Usage](#usage)
    - [View directory](#view-directory)
    - [Render a view](#render-a-view)
    - [Working with namespaces](#working-with-namespaces)
        - [Registering a namespace](#registering-a-namespace)
        - [Using a namespace](#using-a-namespace)
    - [Custom @directives](#custom-directives)
        - [@wpauth()](#wpauth)
        - [@header()](#header)
        - [@footer()](#footer)
        - [@script()](#script)
        - [@style()](#style)
        - [@username()](#username)
        - [@cache()](#cache)
        - [@react()](#react)
- [Credits](#credits)
- [License](#license)

Introduction
============

[](#introduction)

Getting Started
---------------

[](#getting-started)

To get started install the package as described below in [Installation](#installation).

To use the tool have a look at [Usage](#usage)

### Installation

[](#installation)

Install with composer

```
composer require morningtrain/wp-view
```

Dependencies
------------

[](#dependencies)

### illuminate/view

[](#illuminateview)

[illuminate/view](https://github.com/illuminate/view)

### morningtrain/php-loader

[](#morningtrainphp-loader)

[PHP Loader](https://github.com/Morning-Train/php-loader) is used to load and initialize all Hooks

Usage
-----

[](#usage)

For an overview see the [official Laravel documentation](https://laravel.com/docs/views)

### View directory

[](#view-directory)

To set the main directory for views

```
\Morningtrain\WP\View\View::setup(__DIR__ . "/resources/views");
```

### Render a view

[](#render-a-view)

```
echo \Morningtrain\WP\View\View::render('person',['name' => 'John','email' => 'john@doe.com']);
```

### Working with namespaces

[](#working-with-namespaces)

You may register a namespaced for a set of views. This is especially useful when writing plugins as you may group all your plugin views and not worry about duplicate naming. Views in a namespace may be overwritten in the main namespace as long as you use `first()` instead of `render()`.

Eg. `View::first(['vendor/myPlugin/myview','myPlugin::myview])` will render from the vendor dir first if the view exists, thereby allowing theme authors to overwrite this view when necessary.

#### Registering a namespace

[](#registering-a-namespace)

```
echo \Morningtrain\WP\View\View::addNamespace('myPlugin', __DIR__ . "/resources/views");
```

#### Using a namespace

[](#using-a-namespace)

```
echo \Morningtrain\WP\View\View::render('myPlugin::person',['name' => 'John','email' => 'john@doe.com']);
```

### Custom @directives

[](#custom-directives)

This package contains some custom [blade directives](https://laravel.com/docs/blade#blade-directives) that you may use:

#### @wpauth()

[](#wpauth)

```

  @wpauth()
    Hello @username!
  @else
    Login
  @endwpauth

```

#### @header()

[](#header)

Acts the same as : [https://developer.wordpress.org/reference/functions/get\_header/](https://developer.wordpress.org/reference/functions/get_header/)

The following will render the `header.blade.php` view or `header-small.blade.php`

```
@header()
@header('small')
```

#### @footer()

[](#footer)

Acts the same as : [https://developer.wordpress.org/reference/functions/get\_footer/](https://developer.wordpress.org/reference/functions/get_footer/)

The following will render the `footer.blade.php` view or `footer-dark.blade.php`

```
@footer()
@footer('dark')
```

#### @script()

[](#script)

An easy way to enqueue an already registered script.

Using this directive is the same as calling `wp_enqueue_script()` with only the handle.

```
@script('swiper')

  ...

```

#### @style()

[](#style)

An easy way to enqueue an already registered stylesheet.

Using this directive is the same as calling `wp_enqueue_style()` with only the handle.

```
@style('employees')

  ...

```

#### @username()

[](#username)

Prints the username of the currently logged in user or an empty string if no one is logged in.

#### @cache()

[](#cache)

Caches content in a transient and uses the cached data if it exists

```

    Cache test for post: {!! $postId !!}
    @if(!empty($postId))
        @cache("post_card_{$postId}")

            {!! get_the_title($postId) !!}
            {{ get_the_excerpt($postId) }}
            Yes
            {{__('Read more','domain')}}

        @endcache
    @else
        {{__('This is not a post','domain')}}
    @endif

```

#### @react()

[](#react)

Prints a Morningtrain ReactRenderer compatible element with optional props. This makes it easy to prepare components for react to handle in the client.

```
@react('myComponent', [
'someData' => 'someValue'
])
```

The @react directive also supports a child view that will be rendered inside the component-wrapper until the react component is rendered. This is especially useful for skeletons and to avoid popping ins.

```
@react('myComponent', [
'someData' => 'someValue'
],
'my-skeleton-view'),
['skeletonProp' => 'skeletonValue']
```

Credits
-------

[](#credits)

- [Mathias Munk](https://github.com/mrmoeg)
- [Martin Schadegg Brønniche](https://github.com/mschadegg)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.3% of commits — single point of failure

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 ~37 days

Recently: every ~61 days

Total

15

Last Release

1181d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/278725?v=4)[morningtrain](/maintainers/morningtrain)[@morningtrain](https://github.com/morningtrain)

![](https://avatars.githubusercontent.com/u/5990117?v=4)[Mathias Munk](/maintainers/mrmoeg)[@mrmoeg](https://github.com/mrmoeg)

---

Top Contributors

[![mrmoeg](https://avatars.githubusercontent.com/u/5990117?v=4)](https://github.com/mrmoeg "mrmoeg (84 commits)")[![mschadegg](https://avatars.githubusercontent.com/u/11231039?v=4)](https://github.com/mschadegg "mschadegg (7 commits)")[![SimonJnsson](https://avatars.githubusercontent.com/u/11147193?v=4)](https://github.com/SimonJnsson "SimonJnsson (2 commits)")

---

Tags

bladephpwordpresswpwordpressbladetemplatingviewmorningtrain

### Embed Badge

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

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

###  Alternatives

[eftec/bladeone

The standalone version Blade Template Engine from Laravel in a single php file

8259.3M103](/packages/eftec-bladeone)[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.3k449.3k30](/packages/tightenco-jigsaw)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9742.3M121](/packages/roots-acorn)[jenssegers/blade

The standalone version of Laravel's Blade templating engine for use outside of Laravel.

8651.3M114](/packages/jenssegers-blade)[spatie/laravel-blade-comments

Add debug comments to your rendered output

179332.0k](/packages/spatie-laravel-blade-comments)[hasinhayder/tyro-dashboard

Tyro Dashboard - Beautiful admin dashboard for managing Tyro roles, privileges, users, and settings

5452.7k](/packages/hasinhayder-tyro-dashboard)

PHPackages © 2026

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