Mustache View package for the Slim Framework 3+, using bobthecow great PHP implementation of Mustache! ;-)
Using Composer
$ composer require lejahmie/slim-mustache-view
<?php
require 'vendor/autoload.php';
$app = new \Slim\Slim();
$container = $app->getContainer();
$container['view'] = function ($c) {
$mustache = new \Slim\Mustache\Mustache(
'/templates', // Template path
array(
'charset' => 'UTF-8',
),
array(
'extension' => '.html'
)
);
return $mustache;
};
$app->get('/', function (Request $request, Response $response) {
// The render method takes the reponse object,
// template name and finally some data as an array.
$response = $this->view->render($response, "hello", ["foo" => 'bar']);
return $response;
});
Renders the Mustache template with the ResponseInterface used by Slim; $response->getBody()->write($output);
Returns the renderd Mustache template as a string.
Set the template path where Mustache will look for template files.
Set the options for Mustache filesystem loader. See; https://github.com/bobthecow/mustache.php/wiki/Template-Loading
Set the Mustache options. See; https://github.com/bobthecow/mustache.php/wiki
The MIT License (MIT)
- Added method
getRenderedMarkup($templateName, $data)
which allow to fetch the processed markup as raw html string. - Fixed some typos.
- Better readme, because you all read this right? :-D
- First version y'all!