快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

cqlctpl php模板开始提供,最好用,功能最强盛的模板

这个是比较好用的模板,比Smarty,FastTemplate and PHPLIB Template都好用

中文文档案 http://www.cqlc.net/cn_cqlctpl.txt

这里是演示地址:http://www.cqlc.net/web/tml.php

请尊重作者的劳动成果,下面演示的3个文件下载地址:http://www.cqlc.net/cqlctpl.zip

我的主页是:http://www.cqlc.net

1 标签:

(1),变量:{$key} 可以是一般变量,数组和类的成员,但字符不能用 " ,只能是单引号 \\'

例子: {$value} ,{$a[0]} ,{$this->a[\\'color\\']} 这样写是错的{$this->["color"]}

(2),循环:{loop:循环语句}其他代码{/loop} 支持for和while循环

例子: {loop:for($i=10;$i<=20;$i++)} test {$i} {/loop} 输出(test)20~30的数
{loop:while($i++<10)} test {$a[$i]} {/loop} 输出(test)20~30的数组

(3),逻辑:{logi:条件语句}其他代码{/logi} 支持if,elseif,else

例子: {logi:if($i==1)} test {$i} {/logi}
{logi:elseif($i==2)} test {$a[$i]} {/logi}
{logi:else} test {$a[$i]} {/logi}

(4),程序:{exec:语句} 程序段,可以是函数,注重字符只能用 \\',不能用"
例子 : {exec:$a=\\'hello\\'.$i} 准确 {exec:$a="hello$i"}错误
{exec:echo $a}
{exec:echo time()}
{exec:$this->outpage(1,2,\\'index.php\\')}

(5),{* 模板注释*} 例子:{*这里不会输出的*}

2,模板输出 :

只输出:eval(cqlctpl(模板文件)) 例子:eval(cqlctpl("1.tml"))
套模板:{exec:eval(cqlctpl(模板文件))} 例子:{exec:eval(cqlctpl($Templatefile))}
{*这里是在模板中掉用其他模板文件*}

3,函数原代码:

function cqlctpl($file) /*函数作者,cqlc,主页:http://www.cqlc.net,
中文档案 http://www.cqlc.net/cn_cqlctpl.txt */
{
$fp=fopen($file,"r");
$msg="echo/"".str_replace("/"","///"",fread($fp,filesize($file)))."/";";
fclose($fp);
$oldstr=array(0=>"//{loop:([^/}]+)/}(.+)/{//loop/}/si",
1=>"//{logi:([^/}]+)/}(.+)/{//logi/}/si",
2=>"//{exec:([^/}]+)/}/si",
3=>"/(/{/*[^/*]+/*/})/si"
);
$newstr=array(0=>"/";//1{echo/"//2/";}echo/"",
1=>"/";//1{echo/"//2/";}echo/"",
2=>"/";//1;echo/"",
3=>""
);
return preg_replace($oldstr,$newstr,$msg);
}
4,模板举例:

模板文件:1.tml的原代码

<h1> {$title} (1.tml) </h1> {*this is a title*}

{loop:for($i=0;$i<10;$i++)} {*loop start*}

<p> {$body} is {$array[$i]} {*out the msg*}

{logi:if($i>5)} <p> {$i} is biger than 5 {*logic start*}

{/logi} {*login end*}

{/loop} {*loop end*}

{exec:$time=time()} {*exec start and end*}

{exec:echo \\'<p>time is \\'.$time} {*exec start and end*}

{exec:eval(cqlctpl(\\'2.tml\\'))} {*this is include other tml*}

模板文件:2.tml的原代码
<P> <h1>this is other tml(2.tml)</h1>
{ exec:test()}

演示的php脚本
tml.php:
<?
function cqlctpl($file) /*函数作者,cqlc,主页:http://www.cqlc.net,
中文文档案 http://www.cqlc.net/cn_cqlctpl.txt */
{
$fp=fopen($file,"r");
$msg="echo/"".str_replace("/"","///"",fread($fp,filesize($file)))."/";";
fclose($fp);
$oldstr=array(0=>"//{loop:([^/}]+)/}(.+)/{//loop/}/si",
1=>"//{logi:([^/}]+)/}(.+)/{//logi/}/si",
2=>"//{exec:([^/}]+)/}/si",
3=>"/(/{/*[^/*]+/*/})/si"
);
$newstr=array(0=>"/";//1{echo/"//2/";}echo/"",
1=>"/";//1{echo/"//2/";}echo/"",
2=>"/";//1;echo/"",
3=>""
);
return preg_replace($oldstr,$newstr,$msg);
}

function test(){echo"<p>这是第二个模板文件哟 ,欢迎你的测试";} /*定义一个函数*/

$title="这是第一个模板文件";

$body="这里已经开始输出了 ";

for($i=0;$i<10;$i++)$array[$i]="hello world $i";

eval(cqlctpl("1.tml"));


5,模板输出结果,见演示:http://www.cqlc.net/web/tml.php


这是第一个模板文件 (1.tml)
这里已经开始输出了 is hello world 0

这里已经开始输出了 is hello world 1

这里已经开始输出了 is hello world 2

这里已经开始输出了 is hello world 3

这里已经开始输出了 is hello world 4

这里已经开始输出了 is hello world 5

这里已经开始输出了 is hello world 6

6 is biger than 5

这里已经开始输出了 is hello world 7

7 is biger than 5

这里已经开始输出了 is hello world 8

8 is biger than 5

这里已经开始输出了 is hello world 9

9 is biger than 5

time is 1059227729


this is other tml(2.tml)
这是第二个模板文件哟 ,欢迎你的测试





返回类别: 教程
上一教程: PHP/MySQL三日通-第二天(四)
下一教程: php 之 没有mysql支持时的替代方案

您可以阅读与"cqlctpl php模板开始提供,最好用,功能最强盛的模板"相关的教程:
· phplib里带的模板功能的确异常好用,但有个致命的小错误需要更正!
· PHP.MVC的模板标签系统之初识PHP.MVC
· 在PHP世界中选择最合适的模板--比较PHPLIB Template和FastTemplate
· 用PHP制作静态网站的模板框架(三)
· PHP.MVC的模板标签系统(三)
    微笑服务 优质保证 索取样品