bittyphp / view-latte
A Latte template view for Bitty.
v1.0.1
2019-01-19 21:41 UTC
Requires
- php: >=7.1.0
- bittyphp/view: ^2.0
- latte/latte: ^2.4
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-16 12:58:48 UTC
README
A Latte template view for Bitty.
Installation
It's best to install using Composer.
$ composer require bittyphp/view-latte
Setup
Basic Usage
<?php require(dirname(__DIR__).'/vendor/autoload.php'); use Bitty\Application; use Bitty\View\Latte; $app = new Application(); $app->getContainer()->set('view', function () { return new Latte(dirname(__DIR__).'/templates/', $options); }); $app->get('/', function () { return $this->get('view')->renderResponse('index.latte', ['name' => 'Joe Schmoe']); }); $app->run();
Options
<?php use Bitty\View\Latte; $latte = new Latte( dirname(__DIR__).'/templates/', [ // Sets the path to the cache directory. // Defaults to system tmp folder. 'cacheDir' => '/path/to/cache', // Whether to auto-refresh templates when the file changes. 'refresh' => true, // Template content type. // @see Latte\Engine::CONTENT_* constants. 'contentType' => 'html', ] );
Adding Filters
One of the great things about Latte is that you can easily extend it to add you own custom functionality. This view would not be complete without allowing access to that ability.
See Latte's filter docs for more info.
<?php use Bitty\View\Latte; $latte = new Latte(...); $latte->addFilter('someFilterName', function ($value) { return strtolower($value); });
Advanced
If you need to do any advanced customization, you can access the Latte engine and loader directly at any time.
<?php use Bitty\View\Latte; use Latte\Engine; use Latte\ILoader; $latte = new Latte(...); /** @var Engine */ $engine = $latte->getEngine(); /** @var ILoader */ $loader = $latte->getLoader();