bittyphp / view-plates
A Plates template view for Bitty.
v1.0.0
2019-01-20 18:35 UTC
Requires
- php: >=7.1.0
- bittyphp/view: ^2.0
- league/plates: ^3.3
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:39:22 UTC
README
A Plates template view for Bitty.
Installation
It's best to install using Composer.
$ composer require bittyphp/view-plates
Setup
Basic Usage
<?php require(dirname(__DIR__).'/vendor/autoload.php'); use Bitty\Application; use Bitty\View\Plates; $app = new Application(); $app->getContainer()->set('view', function () { return new Plates(dirname(__DIR__).'/templates/', $options); }); $app->get('/', function () { return $this->get('view')->renderResponse('index', ['name' => 'Joe Schmoe']); }); $app->run();
Options
<?php use Bitty\View\Plates; $plates = new Plates( dirname(__DIR__).'/templates/', [ // Sets the extension you want to use. 'extension' => 'php', ] );
Multiple Template Paths
If you have templates split across multiple directories, you can pass in an array with the paths to load from. Each path must have a namespace set as the array key.
The first path in the array will be considered the default.
<?php use Bitty\View\Plates; $plates = new Plates( [ 'public' => 'templates/', 'admin' => 'admin/templates/', ] ); $plates->render('admin::foo'); // Loads admin/templates/foo.php $plates->render('bar'); // Loads templates/bar.php
Advanced
If you need to do any advanced customization, you can access the Plates engine directly at any time.
<?php use Bitty\View\Plates; use League\Plates\Engine; $plates = new Plates(...); /** @var Engine */ $engine = $plates->getEngine();