shakahl / hups-util-phptemplate
基于原生PHP的极轻量级模板类。分支自:https://github.com/lsolesen/php-template/
dev-master
2015-03-15 05:59 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-09-14 17:19:41 UTC
README
介绍
此包是Hups框架的一部分。它是一个基于原生PHP的极轻量级模板类。
此库是从以下地址分支而来:https://github.com/lsolesen/php-template/
安装
https://packagist.org.cn/packages/shakahl/hups-util-phptemplate
将 shakahl/hups-util-phptemplate
添加到 composer.json
作为依赖项
{ "require": { "shakahl/hups-util-phptemplate": "dev-master" } }
使用 composer update
更新您的包,或使用 composer install
安装。
您也可以使用 composer require shakahl/hups-util-phptemplate
添加此包,并稍后指定您想要的版本(目前,dev-master
是最佳选择)。
使用示例
使用示例
<?php
$path = './templates/';
$tpl = new \Hups\Util\PHPTemplate('/path/to/template_file.php');
$tpl->some_title = 'User list';
$tpl->userArray = array(
array(
"id" => 1,
"name" => "John Doe1"
),
array(
"id" => 2,
"name" => "John Doe2"
),
array(
"id" => 3,
"name" => "John Doe3"
)
);
$tpl->set('another_variable', 'some value');
$tpl->assign('another_variable2', 'some value');
$renderedOutput = $tpl->fetch('template-tpl.php');
$tpl->display('template-tpl.php');
?>
示例模板文件
<!-- test_template.tpl.php -->
<h1><?php echo $some_title; ?></h1>
<table>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Banned</th>
</tr>
<?php foreach($userArray as $usr): ?>
<tr>
<td><?php echo $usr['id']; ?></td>
<td><?php echo $usr['name']; ?></td>
</tr>
<?php endforeach; ?>
</table>
<p>
<?php echo $this->another_variable; // Can be used like this ?>
</p>
单元测试
在Windows下
$ composer update
$ vendor/bin/phpunit.bat
在Linux下
$ composer update
$ vendor/bin/phpunit