futape/php-template
Composer 安装命令:
composer require futape/php-template
包简介
A template engine for rendering PHP templates
README 文档
README
This library offers a template engine, which uses PHP files as templates.
Install
composer require futape/php-template
Usage
template.php
Hello <?php echo $name; ?>, this is an usage example of futape/php-template. Your installed PHP version is <?php echo PHP_VERSION; ?>. Here's a list of all defined variables: <?php foreach (get_defined_vars() as $name => $value) { echo $name . ': ' . (string)$value . "\n"; } ?>
renderer.php
use Futape\PhpTemplate\Template; $template = (new Template('template.php')) ->addVariable('name', 'Stranger'); echo $template->render(); /* Hello Stranger, this is an usage example of futape/php-template. Your installed PHP version is 7.2.0. Here's a list of all defined variables: name: Stranger ... */
The template file is executed in its own variable scope and has access to the defined variables only, as well as
superglobals and variables made accessible via global.
Moreover it can access constants and can utilize any PHP functionality you an use in other PHP files as well.
Testing
The library is tested by unit tests using PHP Unit.
To execute the tests, install the composer dependencies (including the dev-dependencies), switch into the tests
directory and run the following command:
../vendor/bin/phpunit
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-24