tiny php template TPT

码农软件 · 软件分类 · 模板引擎 · 2019-08-23 19:12:48

软件介绍


关于TPT

TPT是php实现的用于模板解析小工具,全部实现仅仅60行代码。

配置

DIR_COMPILED和DIR_TEMPLATE,分别表示模版编译目录和模版文件目录:

define('DIR_COMPILED','/compiled_diy');
define('DIR_TEMPLATE','/template_diy');

默默使用compiled和template作为其默认的参数值。

使用方法:

php文件示例:

$title = 'welcome';
$users = array('alen', 'blen', 'calon');
include template('main');


header.html模版文件示例:

<html>
<head>
    <meta http-equiv=content-type content="text/html; charset=UTF-8">
    <title>{$title}</title>
</head>
<body>


main.html模版文件示例:

<!--{include header}-->
<!--{loop $users $index $one}-->
<li>${$index+1}-{$one}</li>
<!--{/loop}-->
<!--{include footer}-->


{}作为模版引擎的开始和结束标记,如果{}内部使用php运算符、函数调用等复杂语句,则需在{前加$,正确输出:

1-alen
2-blen
3-calon


footer.html模版文件示例:

</body>
</html>


否则,标记里面的内容不会被解析,输出如下:

{$index+1}-alen
{$index+1}-blen
{$index+1}-calon


模版中可以使用简单的php控制结构,下面的示例中包含了循环结构的使用,另外,还支持if,if/else,if/elseif/else等条件判断,本模版本着“大道至简”的设计思想,简单实用就已经足够了,所以,也仅仅支持这两种控制结构。

<!--{loop $users $index $one}-->
<!--{if $index==0}-->
<li>${md5($one)}-{$one}</li>
<!--{elseif $index==1}-->
<li>${md5($one)}-{$one}</li>
<!--{else}-->
<li>${md5($one)}-{$one}</li>
<!--{/if}-->
<!--{/loop}-->


输出:

f3f7eb1421dcfed9a2614712ec608f1b-alen
37670a9c2cc598bcc271612af0617c3c-blen
82a8ea39dd2700b9c6dd207d512bb62a-calon





本文地址:https://www.codercto.com/soft/d/13017.html

Beginning iPhone and iPad Web Apps

Beginning iPhone and iPad Web Apps

Chris Apers、Daniel Paterson / Apress / 2010-12-15 / USD 39.99

It seems that everyone and her sister has developed an iPhone App—everyone except you, the hard-working web professional. And now with the introduction of the iPad, you may even feel farther behind. B......一起来看看 《Beginning iPhone and iPad Web Apps》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

MD5 加密
MD5 加密

MD5 加密工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换