PHPackages                             avatarguru/mustache-l5 - 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. avatarguru/mustache-l5

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

avatarguru/mustache-l5
======================

A Mustache.php wrapper for Laravel 5

12306[2 issues](https://github.com/avatarguru/mustache-l5/issues)[1 PRs](https://github.com/avatarguru/mustache-l5/pulls)PHP

Since Sep 23Pushed 10y ago1 watchersCompare

[ Source](https://github.com/avatarguru/mustache-l5)[ Packagist](https://packagist.org/packages/avatarguru/mustache-l5)[ RSS](/packages/avatarguru-mustache-l5/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

laravel5-mustache
=================

[](#laravel5-mustache)

A Mustache.php wrapper for Laravel v4 | v5

Install
=======

[](#install)

Add mustache-l5 as a dependency to your `composer.json` file

```
"require": {
	"laravel/framework": "4.2.*",
	"avatarguru/mustache-l5": "dev-master"
}
```

run `composer update`, or `composer install` if this is a brand new project

Add the Service Provider

app/config/app.php

```
...

'Avatarguru\MustacheL5\MustacheL5ServiceProvider',

...
```

You are all setup!

Usage
=====

[](#usage)

Mustache-L5 is merely a wrapper for the [Mustache.php](https://github.com/bobthecow/mustache.php) library that integrates it into Laravel 4.

Mustache-L5 registers itself with the Laravel View class, providing seemless integration with Laravel. You can use Mustache just as you would Blade! The Laravel View class will choose the right templating engine to use based on the file extension of the view. So all you have to do to render Mustache files, is ensure that your view has a `.mustache` file extension. Mustache-L4 will take care of the rest.

You can even mix and match template engines. For instance maybe you have a Blade layout file, and you want to nest a Mustache view, thats fine! However just be aware of the fact that Mustache does not understand Block Sections like Blade does. The Mustache view will be rendered into a variable named whatever section you passed the view to. So for example if you were to do:

```
$this->layout->nest('content', 'some.view');
$this->layout->nest('sidebar', 'some.sidebar');
```

The contents of the parsed `some.view` file will be available in the template file under a variable called `$content`. The contents of the parsed `some.sidebar` would be availble in the template file, under a variable called `$sidebar`.

By default, Mustache partials are also loaded using Laravel's ViewFinder, so you can feel free to use dot-notation to specify a view.

```
{{#posts}}
	{{> posts._post}}
{{/posts}}
```

Other than that it is business as usual!

Examples:
=========

[](#examples)

- Example using View::make()

    app/views/test.mustache

    ```
      {{ pageHeading }}

      	{{ pageContent }}

    ```

    app/router.php

    ```
      Route::get('/', function()
      {
      	return View::make('test', array(
      		'pageHeading' => 'Rendered with Mustache.php',
      		'pageContent' => 'But still looks like Laravel!'
      	));
      });

    ```
- Example using a Blade controller layout

    app/views/layouts/master.blade.php

    ```

      	{{-- since Mustache does not use sections, the nested section will instead
      	be rendered as a variable --}}
      	{{ content }}

    ```

    app/views/test.mustache

    ```
      {{ pageHeading }}

      	{{ pageContent }}

    ```

    app/controllers/TestController.php

    ```
