ichigotake / nano-template
使用 PHP5 语言的 Nano 模板引擎
dev-master
2013-12-07 02:52 UTC
Requires
- php: >=5.3.3
This package is not auto-updated.
Last update: 2024-09-23 15:33:03 UTC
README
NanoTemplate - 使用 PHP5 语言的 Nano 模板引擎
用法
所有功能都在示例中。这个模块非常简单!
非常简单的调用
require 'lib/NanoTemplate.php';
# render($view_file, $binds, $charset);
#
# The second and the following arguments is optional.
# Default charset is "UTF-8"
render('/path/to/view.php', array(
'greet' => 'hahaha',
'greet_jp' => 'ごきげんよう',
));
或者,创建实例
### index.php
# param(optional): ($view = 'view/', $charset = 'UTF-8')
$t = new NanoTemplate('view/');
# echo template with bind variable
$t->render('template.php', array(
'greet' => 'Hello!!',
'greet_jp' => 'こんにちは!',
));
### view/template.php
<?php $_layout = 'layout.php' ?>
<?php echo $greet_jp ?> (Japanese mean "<?php echo $greet ?>")
### view/layout.php
<!doctype html>
<html>
<head>
</head>
<body>
<?php echo $_content ?>
</body>
</html>
为什么命名为 Nano?
PHP 模板引擎已经存在很多了。但几乎所有的都依赖于大型或 Web 应用程序框架。
NanoTemplate 没有扩展语法,并且分配的变量不是 '$this'。此外,如果您想分配对象变量;)
NanoeTemplate 只有一个纯 PHP 文件。PHP 是模板引擎本身,因为命名为 'Nano'。
作者
ichigotake