2017 © Pedro Peláez
 

library laratash

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

image

brightmachine/laratash

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

  • Tuesday, December 12, 2017
  • by brightmachine
  • Repository
  • 2 Watchers
  • 11 Stars
  • 8,286 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 9 Versions
  • 8 % Grown

The README.md

laratash

A Laravel wrapper for mustache.php, a PHP implementation of http://mustache.github.io/, (*1)

Acknowledgements

This project is based entirely on the the mustache-l4 package by Conar Welsh and contributors., (*2)

Supports

  • Laravel 5
  • mustache/mustache 2.7+

Installation

Add laratash as a dependency to your composer.json file:, (*3)

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

run composer update, or composer install if this is a brand new project, (*4)

Add the Service Provider

Open: config/app.php, (*5)

...

'Laratash\LaratashServiceProvider',

...

You are all setup!, (*6)

Usage

Laratash is merely a wrapper for the Mustache.php library that integrates it into Laravel 5+., (*7)

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., (*8)

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:, (*9)

$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., (*10)

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

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

Other than that it is business as usual!, (*12)

Examples:

  • Example using View::make(), (*13)

    app/views/test.mustache, (*14)

    <h1>{{ pageHeading }}</h1>
    <div>
        {{ pageContent }}
    </div>

    app/router.php, (*15)

    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, (*16)

    app/views/layouts/master.blade.php, (*17)

    <html>
    <head></head>
    <body>
        {{-- since Mustache does not use sections, the nested section will instead
        be rendered as a variable --}}
        {{ content }}
    </body>
    </html>

    app/views/test.mustache, (*18)

    <h1>{{ pageHeading }}</h1>
    <div>
        {{ pageContent }}
    </div>

    app/controllers/TestController.php, (*19)

    <?php
    
    class TestController extends BaseController {
    
        public $layout = 'layouts.master';
    
        public function index()
        {
        $this->layout->nest('content', 'test', array(
            'pageHeading' => 'Rendered with Mustache.php',
            'pageContent' => 'But still looks like Laravel!'
        ));   
        }
    
        }
  • Example using a Mustache layout, (*20)

    app/views/posts/_post.mustache, (*21)

    <article>
        <h2>{{ title }}</h2>
        <div>
            {{ content }}
        </div>
    </article>

    app/views/blog/index.mustache, (*22)

    <html>
    <head></head>
    <body>
        <h1>My Blog</h1>
    
        {{#posts}}
            {{> posts._post}}
        {{/posts}}
    </body>
    </html>

    app/routes.php, (*23)

    Route::get('/', function()
    {
        $posts = array(
            array(
                'title' => 'This is a Title',
                'content' => 'lorem ipsum...'
            ),
            array(
                'title' => 'This is a another title',
                'content' => 'lorem ipsum...'
            ),
            array(
                'title' => 'This is yet another Title',
                'content' => 'lorem ipsum...'
            ),
        );
    
        return View::make('blog.index', compact('posts));
    });

A note on template data

Laravel expects view data to be be passed as an array., (*24)

Mustache PHP, however, also allows a Context object to be used., (*25)

If you wish to use a Context object, pass through an array with a __context key and this will be used. E.g., (*26)

`return view('my.view', ['__context' => new Context]);`

Configure

You can alter the configuration options that are passed to Mustache.php in your ConfigServiceProvider. E.g., (*27)

config([
    'laratash.cache' => storage_path() . '/framework/views/mustache',
]);

All laratash. options are passed directly to the Mustache_Engine constructor, so you can use any of the options that you would use with Mustache.php, (*28)

The Versions

12/12 2017

dev-master

9999999-dev https://github.com/brightmachine/laratash

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

  Sources   Download

MIT

The Requires

 

by Conar Welsh
by Kelvin Jones

laravel php mustache laravel 5

12/12 2017

5.0.7

5.0.7.0 https://github.com/brightmachine/laratash

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

  Sources   Download

MIT

The Requires

 

by Conar Welsh
by Kelvin Jones

laravel php mustache laravel 5

20/01 2017

5.0.6

5.0.6.0 https://github.com/brightmachine/laratash

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

  Sources   Download

MIT

The Requires

 

by Conar Welsh
by Kelvin Jones

laravel php mustache laravel 5

08/02 2015

5.0.5

5.0.5.0 https://github.com/brightmachine/laratash

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

  Sources   Download

MIT

The Requires

 

by Conar Welsh
by Kelvin Jones

laravel php mustache laravel 5

02/02 2015

5.0.4

5.0.4.0 https://github.com/brightmachine/laratash

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

  Sources   Download

MIT

The Requires

 

by Conar Welsh
by Kelvin Jones

laravel php mustache laravel 5

14/11 2014

5.0.3

5.0.3.0 https://github.com/brightmachine/laratash

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

  Sources   Download

MIT

The Requires

 

by Conar Welsh
by Kelvin Jones

laravel php mustache laravel 5

23/09 2014

5.0.2

5.0.2.0 https://github.com/brightmachine/laratash

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

  Sources   Download

MIT

The Requires

 

by Conar Welsh
by Kelvin Jones

laravel php mustache laravel 5

20/09 2014

5.0.1

5.0.1.0 https://github.com/brightmachine/laratash

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

  Sources   Download

MIT

The Requires

 

by Conar Welsh
by Kelvin Jones

laravel php mustache laravel 5

20/09 2014

5.0.0

5.0.0.0 https://github.com/brightmachine/laratash

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

  Sources   Download

MIT

The Requires

 

by Conar Welsh
by Kelvin Jones

laravel php mustache laravel 5