phpolar / php-templating
This package is abandoned and no longer maintained.
The author suggests using the phpolar/pure-php package instead.
Pure PHP Templates
2.0.0
2023-09-02 23:44 UTC
Requires
- php: >= 8.1
Requires (Dev)
- ext-mbstring: *
- phan/phan: ^5.4
- php-coveralls/php-coveralls: ^2.5
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^10.0
- squizlabs/php_codesniffer: ^3.7
- dev-main
- 2.0.0
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.5.0
- 0.4.0
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.0
- 0.1.2
- 0.1.1
- 0.1.0
- dev-upgrade-phpunit
- dev-upgrade-deps
- dev-lint-config-fix
- dev-dependabot/composer/phpstan/phpstan-1.11.2
- dev-dependabot/composer/squizlabs/php_codesniffer-3.10.1
- dev-dependabot/composer/phpunit/phpunit-10.5.20
- dev-dependabot/composer/phpmd/phpmd-2.15.0
- dev-dependabot/composer/php-coveralls/php-coveralls-2.7.0
- dev-update-readme
This package is auto-updated.
Last update: 2024-05-27 04:20:40 UTC
README
Pure PHP
Templating that's just PHP. That's it. Seriously.
Support using pure PHP templates with automatic XSS mitigation.
Table of Contents
Installation
composer require phpolar/pure-php
Usage
$page = new Page(); $safeContext = new HtmlSafeContext($page); $templateEng->render("path/to/template.php", $safeContext); // or... echo $templateEng->apply("path/to/template", $safeContext /* optional */);
Template Basename Only
// or... echo $templateEng->apply("template", $safeContext /* optional */); // or... echo $templateEng->apply("template", $safeContext /* optional */);
The template engine will look for files with .php, .phtml, or .html extensions in
src/templates
directory relative to the current working directory.
Example 1
Pure PHP Templates
// template.php <!DOCTYPE html> <?php /** * @var Page $view */ $view = $this; ?> <html> <head> <style> body { font-family: <?= $view->font ?>; padding: 0; margin: 0; } form th { text-align: right; } form td { text-align: left; } .container { background-color: <?= $view->backgroundColor ?>; padding: 20px 0 90px } </style> </head> <body style="text-align:center"> <h1><?= $view->title ?></h1> <div class="container"> </div> </body> </html>
// Page.php class Page { public string $title; public string $backgroundColor = "#fff"; public string $font = "Arial"; public function __construct(string $title) { $this->title = $title; } }