lejahmie / slim-mustache-view
Mustache View package for the Slim Framework
v2.0
2017-02-15 15:01 UTC
Requires
- mustache/mustache: ^2.11
- psr/http-message: ^1.0
- slim/slim: ^3.0
This package is not auto-updated.
Last update: 2024-05-11 18:02:01 UTC
README
Mustache View package for the Slim Framework 3+, using bobthecow great PHP implementation of Mustache! ;-)
How to install
Using Composer
$ composer require lejahmie/slim-mustache-view
How to use
<?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; });
Methods
render($templateName, $data)
Renders the Mustache template with the ResponseInterface used by Slim; $response->getBody()->write($output);
getRenderedMarkup($templateName, $data)
Returns the renderd Mustache template as a string.
setTemplatePath($templatePath)
Set the template path where Mustache will look for template files.
setLoaderOptions($loaderOptions)
Set the options for Mustache filesystem loader. See; https://github.com/bobthecow/mustache.php/wiki/Template-Loading
setOptions($options)
Set the Mustache options. See; https://github.com/bobthecow/mustache.php/wiki
Authors
License
The MIT License (MIT)
Change log
1.0.1
- 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
1.0
- First version y'all!