PHPackages                             brightmachine/laratash - 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. brightmachine/laratash

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

brightmachine/laratash
======================

A Laravel 5+ wrapper for mustache.php, a PHP implementation of http://mustache.github.io/

5.0.7(8y ago)1214.8k↓76.7%7MITPHPPHP &gt;=5.4.0

Since Sep 20Pushed 8y ago2 watchersCompare

[ Source](https://github.com/brightmachine/laratash)[ Packagist](https://packagist.org/packages/brightmachine/laratash)[ Docs](https://github.com/brightmachine/laratash)[ RSS](/packages/brightmachine-laratash/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (4)Versions (9)Used By (0)

laratash
========

[](#laratash)

A Laravel wrapper for mustache.php, a PHP implementation of

Acknowledgements
================

[](#acknowledgements)

This project is based entirely on the the [mustache-l4](https://github.com/conarwelsh/mustache-l4) package by Conar Welsh and contributors.

Supports
--------

[](#supports)

- `Laravel 5`
- `mustache/mustache 2.7+`

Installation
============

[](#installation)

Add laratash as a dependency to your `composer.json` file:

```
"require": {
	"laravel/framework":      "~5.0",
	"brightmachine/laratash": "~5.0"
}
```

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

Add the Service Provider
------------------------

[](#add-the-service-provider)

Open: `config/app.php`

```
...

'Laratash\LaratashServiceProvider',

...
```

You are all setup!

Usage
=====

[](#usage)

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

Laratash registers itself with the Laravel View class, providing seamless integration with Laravel. You can use Mustache just as you would Blade! The Laravel View class will choose the right template 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. Laratash 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, that's 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:

```
$view->nest('content', 'some.view');
$view->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 available 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

    ```
