bittyphp / view-mustache
A Mustache template view for Bitty.
v2.0.1
2019-01-19 21:51 UTC
Requires
- php: >=7.1.0
- bittyphp/view: ^2.0
- mustache/mustache: ^2.5
Requires (Dev)
- codacy/coverage: ^1.4
- jakub-onderka/php-parallel-lint: ^1.0
- localheinz/composer-normalize: ^1.1
- phing/phing: ^2.16
- phpstan/phpstan: ^0.10.7
- phpstan/phpstan-deprecation-rules: ^0.10.2
- phpstan/phpstan-phpunit: ^0.10.0
- phpstan/phpstan-strict-rules: ^0.10.1
- phpunit/phpunit: ^7.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2023-05-10 16:34:00 UTC
README
A Mustache template view for Bitty.
Installation
It's best to install using Composer.
$ composer require bittyphp/view-mustache
Setup
You can use any valid Mustache Engine options, except loader
which is defined automatically. Another difference is the option strict_callables
is set to true by default.
Basic Usage
<?php require(dirname(__DIR__).'/vendor/autoload.php'); use Bitty\Application; use Bitty\View\Mustache; $app = new Application(); $app->getContainer()->set('view', function () { return new Mustache(dirname(__DIR__).'/templates/', $options); }); $app->get('/', function () { return $this->get('view')->renderResponse('index', ['name' => 'Joe Schmoe']); }); $app->run();
Multiple Template Paths
If you have templates split across multiple directories, you can pass in an array with the paths to load from.
<?php use Bitty\View\Mustache; $mustache = new Mustache( [ 'templates/', 'views/', ] ); $mustache->render('foo'); // Looks for the following templates until it finds one: // 'templates/foo.mustache' // 'views/foo.mustache'
Custom Extension
By default, Mustache looks for files with a .mustache
extension. You can provide an extension
option to set it to something else.
<?php use Bitty\View\Mustache; $mustache = new Mustache( 'templates/', [ 'extension' => 'html', ] ); // Both of these will look for 'templates/foo.html' $mustache->render('foo'); $mustache->render('foo.html');
Advanced
If you need to do any advanced customization, you can access the Mustache engine directly at any time.
<?php use Bitty\View\Mustache; $mustache = new Mustache(...); /** @var Mustache_Engine */ $engine = $mustache->getEngine();