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://codercto.com/soft/d/13017.html

Spring实战(第4版)

Spring实战(第4版)

Craig Walls 沃尔斯 / 张卫滨 / 人民邮电出版社 / 2016-4-1 / CNY 89.00

《Spring实战(第4版)》是经典的、畅销的Spring学习和实践指南。 第4版针对Spring 4进行了全面更新。全书分为四部分。第1部分介绍Spring框架的核心知识。第二部分在此基础上介绍了如何使用Spring构建Web应用程序。第三部分告别前端,介绍了如何在应用程序的后端使用Spring。第四部分描述了如何使用Spring与其他的应用和服务进行集成。 《Spring实战(第4......一起来看看 《Spring实战(第4版)》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具