litphp / view-php
A view that use native PHP to render output for lit
v0.9.0
2019-06-29 13:36 UTC
Requires
- litphp/air: ^0.9
- litphp/voltage: ^0.9
- slim/php-view: ^2.2.1
Requires (Dev)
- phpstan/phpstan-phpunit: ^0.11.2
- phpstan/phpstan-shim: ^0.11.7
- phpunit/phpunit: ^7.5
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-10-29 05:40:43 UTC
README
Native php templating for lit
with slim/php-view
Usage
In a standard litphp/project:
- add dependency & install
composer require litphp/view-php
- append configuration
Create a template dir in your project root, says template
. Write your first template file templates/index.phtml
Hello <?=name?>!
Merge PhpView::configuration
into your configuration.php
. (with parameter of \Slim\Views\PhpRenderer
)
$configuration+=\Lit\View\Php\PhpView::configuration([__DIR__.'/templates']);
- integration in action class
In src/BaseAction.php
, use the trait PhpViewBuilderTrait
abstract class BaseAction extends BoltAbstractAction { use \Lit\View\Php\PhpViewBuilderTrait;
Change your src/HomeAction.php
to render page
class HomeAction extends BaseAction { protected function main(): ResponseInterface { return $this->template('index.phtml')->render(['name' => 'native php']); }
That's all! Run your app by php -S 127.0.0.1:3080 public/index.php
, and open http://127.0.0.1:3080/. You should see greetings from template "Hello native php!"