免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: HonestQiao

[模板 下载地址更新] SmartTemplate(适用于企业级PHP开发的模板引擎) [复制链接]

论坛徽章:
0
发表于 2005-08-16 15:46 |显示全部楼层

[模板] SmartTemplate(适用于企业级PHP开发的模板引擎)

好象很不错似的哦!要试试!

论坛徽章:
0
发表于 2005-08-16 16:51 |显示全部楼层

[模板] SmartTemplate(适用于企业级PHP开发的模板引擎)

请教HonestQiao兄,
关于SmartTemplate模板嵌套,教程上是这样写的
有两个模板文件:
一、--table.tpl--
<html>;
<head>;
</head>;
<body>;

<p align="center">;<strong>;<font color="#FF0000" size="5">;{TITLE}</font>;</strong>;</p>;
<p align="center">;--------------------------------------------------------------
</p>;
<Table width="75%" border="1" align="center">;
{CONTENT}
</table>;
</body>;
</html>;

----------------------------

二、--table_content.tpl--
<tr>;
<td>;{TD1}</td>;
<td>;{TD2}</td>;
</tr>;
----------------------------
要实现的目的是将 table_content.tpl 中的模板内容嵌入到 table.tpl 模板中形成一个完整的表格,具体实现的程序如下:
--start table.php --------------------
<?
require_once "./class/class.smarttemplate.php";

//对表格行列数据符值

$info = new SmartTemplate( "./templates/table_content.tpl" );

$info->;assign('TD1','TD1');
$info->;assign('TD2','TD2');

//$info->;output();

$result=$info->;result();

//对表格整体进行赋值

$index = new SmartTemplate( "./templates/table.tpl" );

$index->;assign ('TITLE','这是一个表格模板试验程序');

$index->;assign('CONTENT',$result);

$index->;output();

?>;

我的测试,
<?php
require "./admin/class/class.smarttemplate.php";
$t = new SmartTemplate("link.htm";
$t->;assign("link",$link);
$link_data = $t->;result();
$time = date("Y-m-d g:i A",time());
$index = new SmartTemplate("index.htm";
$index->;assign("time",$time);
$index->;output();
?>;
为什么index.htm中{time}无返回值呀,

论坛徽章:
0
发表于 2005-08-16 18:44 |显示全部楼层

[模板] SmartTemplate(适用于企业级PHP开发的模板引擎)

一直有个问题想问...
为什么模板技术不做成php_extension呢?

论坛徽章:
0
发表于 2005-08-16 19:43 |显示全部楼层

[模板] SmartTemplate(适用于企业级PHP开发的模板引擎)

不做成标准的扩展库是因为php自己本身就是一个模版,为了速度、灵活应该用php自己作为模版,smarty大概一年半前就成熟应用,smarttemplate大概一年前也应用过,它们的缺点很明显——慢。如果不在特殊情况下例如由客户自己编辑模版文件(CMS)的话而,系统是crm、ehr、oa等那就应该回php本身。

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
发表于 2005-08-16 21:08 |显示全部楼层

[模板] SmartTemplate(适用于企业级PHP开发的模板引擎)

原帖由 "Unicorn_angel" 发表:
请教HonestQiao兄,
关于SmartTemplate模板嵌套,教程上是这样写的
有两个模板文件:
一、--table.tpl--
<html>;
<head>;
</head>;
<body>;

<p align="center">;<strong&..........


呵呵,不知道你在什么地方看的这样子的教程?
而且你这样子的嵌套,实际上对于模板来说,非常不好。
因为你把表格的tr提取出来,这个可是很不好设计的。

而且,你没有告诉我们,你的{time}是怎么在页面占位的,实际上,你可以直接:
<html>;
{tiem}
</html>;




标准的测试,应该为:
一、--table.tpl--
<html>;
<head>;
</head>;
<body>;

<p align="center">;<strong>;<font color="#FF0000" size="5">;{TITLE}</font>;</strong>;</p>;
<p align="center">;--------------------------------------------------------------
</p>;
<Table width="75%" border="1" align="center">;
<!-- BEGIN CONTENT -->;
<tr>;
<td>;{TD1}</td>;
<td>;{TD2}</td>;
</tr>;
<!-- END CONTENT -->;
</table>;
</body>;
</html>;

--start table.php --------------------
<?
require_once "./class/class.smarttemplate.php";

//对表格行列数据符值

$result[]=('TD1'=>;'TD1','TD2'=>;'TD2');

//对表格整体进行赋值

$index = new SmartTemplate( "./templates/table.tpl" );

$index->;assign ('TITLE','这是一个表格模板试验程序');

$index->;assign('CONTENT',$result);

$index->;output();

?>;

论坛徽章:
0
发表于 2005-08-17 09:55 |显示全部楼层

[模板] SmartTemplate(适用于企业级PHP开发的模板引擎)

问题解决,呵,看来以后看在网站找资料先要验证一下准确性了,

开始喜欢上SmartTemplate了,

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
发表于 2005-08-17 18:35 |显示全部楼层

[模板] SmartTemplate(适用于企业级PHP开发的模板引擎)

原帖由 "Unicorn_angel" 发表:
问题解决,呵,看来以后看在网站找资料先要验证一下准确性了,

开始喜欢上SmartTemplate了,



呵呵,后面还有一部分,这几天不忙的时候继续帖上来。

这个东西轻巧简洁,不错

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
发表于 2005-08-18 11:48 |显示全部楼层

[模板] SmartTemplate(适用于企业级PHP开发的模板引擎)

SmartPHP 例子: begin end

begin ... end 结构提供了一种方法,使用数字索引数组来输出重复的相似的内容。数字索引数组的每一个元素,应该是一个散列数组,<!-- begin -->; and <!-- end -->; 标签类似一个小的模板,他分析内嵌的模板片断,并使用这个散列数组来生成内容。

每个散列数组可以使用以下的两个扩展参数:

ROWCNT :当前元素的在父数组之中的实际位置. (0,1,2,3,...n)
ROWBIT : 表示ROWCNT的二进制字节的最后一位,也就是奇偶值. (0,1,0,1,0,1,...)

begin ... end 块可以很容易的嵌套使用,他们会被自动的递归分析.
begin_end.php: (  Download)
  1. <?php

  2.     require_once "class.smarttemplate.php";
  3.     $page = new SmartTemplate("begin_end.html");

  4.     $users = array(
  5.                array( 'NAME' =>; 'John Doe',   'GROUP' =>; 'ADMIN' ),
  6.                array( 'NAME' =>; 'Jack Doe',   'GROUP' =>; 'SUPPORT' ),
  7.                array( 'NAME' =>; 'James Doe',  'GROUP' =>; 'GUEST' ),
  8.                array( 'NAME' =>; 'Jane Doe',   'GROUP' =>; 'GUEST' ),
  9.              );

  10.     $page->;assign( 'users',  $users );

  11.     $page->;output();

  12. ?>;
复制代码


begin_end.php使用的模板如下:
begin_end.html: (  Download)
  1. <style type="text/css">;
  2. .col0 { background-color: #D0D0D0; }
  3. .col1 { background-color: #F0F0F0; }
  4. </style>;

  5. <table border="1" cellpadding="2" cellspacing="0">;
  6. <tr>;
  7. <th>; No </th>;
  8. <th>; Username </th>;
  9. <th>; Usergroup </th>;
  10. </tr>;

  11. <!-- BEGIN users -->;

  12. <tr class="col{ROWBIT}">;
  13. <td>; {ROWCNT} </td>;
  14. <td>; {NAME} </td>;
  15. <td>; {GROUP} </td>;
  16. </tr>;

  17. <!-- END users -->;

  18. </table>;
复制代码


begin_end.php的运行效果如下:
输出: (  查看)
  1. <style type="text/css">;
  2. .col0 { background-color: #D0D0D0; }
  3. .col1 { background-color: #F0F0F0; }
  4. </style>;

  5. <table border="1" cellpadding="2" cellspacing="0">;
  6. <tr>;
  7. <th>; No </th>;
  8. <th>; Username </th>;
  9. <th>; Usergroup </th>;
  10. </tr>;


  11. <tr class="col0">;
  12. <td>; 0 </td>;
  13. <td>; John Doe </td>;
  14. <td>; ADMIN </td>;
  15. </tr>;


  16. <tr class="col1">;
  17. <td>; 1 </td>;
  18. <td>; Jack Doe </td>;
  19. <td>; SUPPORT </td>;
  20. </tr>;


  21. <tr class="col0">;
  22. <td>; 2 </td>;
  23. <td>; James Doe </td>;
  24. <td>; GUEST </td>;
  25. </tr>;


  26. <tr class="col1">;
  27. <td>; 3 </td>;
  28. <td>; Jane Doe </td>;
  29. <td>; GUEST </td>;
  30. </tr>;


  31. </table>;
复制代码

论坛徽章:
0
发表于 2005-08-19 11:37 |显示全部楼层

[模板] SmartTemplate(适用于企业级PHP开发的模板引擎)

[quote]原帖由 "unixdotnet"]不做成标准的扩展库是因为php自己本身就是一个模版,为了速度、灵活应该用php自己作为模版,smarty大概一年半前就成熟应用,smarttemplate大概一年前也应用过,它们的缺点很明显——慢。如果不在特殊情况下例如由客�.........[/quote 发表:

当然,我明白你的意思.但就象c也可以使用面向对象的技术一样.
毕竟用php写模版肯定不如smarty方便.这也是模板技术产生的原因.

楼主的这个smarttemplate不是也把模版转化成php模板提高速度吗?
换个角度来看,模版技术更象是一种转换工具.
而假如有php扩展来自动提供这种转换不是更好吗?

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
发表于 2005-08-21 13:11 |显示全部楼层

[模板] SmartTemplate(适用于企业级PHP开发的模板引擎)

一个简单的演示,大家可以看看,因为商业性质开发,所以暂时不便公开源代码,等二次整理之后可以公布:
http://www.moment.com.cn/album.php?AlbumAction=Menu

刚才用SmartTemplate做了一个小东西,使用FTP直接上传图图库,然后在线浏览:
http://www.moment.com.cn/templates/default/album/Menu.htm
菜单模板
http://www.moment.com.cn/templates/default/album/Album.htm
相册分页模板
http://www.moment.com.cn/templates/default/album/List.htm
图片列表模板

没有美化的,便于教学。


List部分代码

  1. ......
  2.         if($AlbumAction == "List") {
  3.                 $LIST = array();
  4.                 for($i=0;$i<count($Album_List)/$Album_Td;$i++)
  5.                 {
  6.                         for($j=0;$j<$Album_Td;$j++)
  7.                         {
  8.                                 if(empty($Album_List[$i*$Album_Td+$j])) {
  9.                                 }
  10.                                 else {
  11.                                         $LIST[$i]["LISTTD"][$j]["LINK"] = "$Album_Url/$AlbumDir/$AlbumPage/{$Album_List[$i*$Album_Td+$j]}";
  12.                                         $LIST[$i]["LISTTD"][$j]["NAME"] = "[{$Album_List[$i*$Album_Td+$j]}]";
  13.                                         $LIST[$i]["LISTTD"][$j]["OBJID"] = $i*$Album_Td+$j;
  14.                                 }
  15.                         }

  16.                 }

  17.                 $tpl->;assign("LIST",$LIST);
  18.                 $tpl->;output();
  19.                 exit;
  20.         }               

  21. .......
复制代码
TREE.JPG
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP