danjam / slim-mustache-view
Simple Slim 3 framework view renderer for mustache templates using Mustache.php
Installs: 53 562
Dependents: 1
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=5.5.0
- mustache/mustache: ^2.0
- psr/http-message: ^1.0
Requires (Dev)
- phpunit/phpunit: ^4.6.0
- satooshi/php-coveralls: dev-master
- slim/slim: ^3.0.0
This package is auto-updated.
Last update: 2024-11-29 00:50:20 UTC
README
Simple Slim 3 framework view renderer for mustache templates using Mustache.php
Install
Via Composer
$ composer require danjam/slim-mustache-view
Usage
// create Slim 3 app $app = new \Slim\App(); // get the container $container = $app->getContainer(); // register Mustache view $container['view'] = function ($container) { $view = new \Slim\Views\Mustache(); return $view; }; // define the route $app->get('/hello/{name}', function ($request, $response, $args) { return $this->view->render($response, 'Hello, {{name}}', [ 'name' => $args['name'] ]); }); // run the app $app->run();
The constructor takes an optional array of Mustache.php options. See the Mustache.php documentation for details.
// register Mustache view $container['view'] = function () { $view = new \Slim\Views\Mustache([ 'cache' => './cache/mustache', 'loader' => new Mustache_Loader_FilesystemLoader('./views'), 'partials_loader' => new Mustache_Loader_FilesystemLoader('./views/partials') ]); return $view; };
You can also capture raw template contents if needed. This can be useful for rendering inline templates, for example when also using mustache.js
$this->view->getRawTemplate('some-template.html');
Testing
phpunit
Credits
License
The MIT License (MIT). Please see License File for more information.