iptton 发表于 2007-1-12 13:51

smarty&SO ON学习笔记 (不发新帖了...网页相关的都发这来)

用几个小时把SMARTY类的电子书大致翻了下
摘录了SMARTY的若干特性
做个笔记:




1,安装:
  所谓“安装”,就是让PHP能够找到Smarty.class.php文件
  最简单的办法是把下载的SMARTY解压到你的项目上
  稍复杂的办法是改php.ini 的include_path目录
2,从配置文件引用变量
x.tpl
{config_load file="sample.conf"}
   <html><head>
<title>{#title#}</title>
   </head>
   <body>
另一种表达法:<a href="" title="{$smarty.config.title}">HEllo</a>
注意:是smarty.config而非实例化后的smarty对象
   </body>
</html>
sample.conf
title="Hello config_file"
3,{$smarty}保留变量
3.1 Request Variables (get post server session四个)
3.2 now constcapture configsection foreachtemplate
用法:
{$smarty.get.page}

capture:
{capture name="button"}
<input type="button" value="Capture" />
{/capture}
{if $smarty.capture.button ne ""}
{$smarty.capture.button}
{/if}
4格式符:
{$var|format:"format string"}
例:{$title|default:"no title"}
    {$redirectUrl|escape:"url"}
  {$articleTitle|nl2br} newline(即\n) to <br />
    {$articleTitle|regex_replace:"/查找表达式/":"替换表达式"}
    {$test|replace:"要替换的内容":"替换成的内容"}

5 怎么输出{}??
{ldelim}{rdelim}
6 类似于 echo <<< _html;
         <a href="" >adfs</a>
         -html;
的功能:{literal}{/literal}(smarty内部是否就是这样实现?)
7{php}{/php}
8 简写的DataGrid颜色分层
{section name=rows loop=$data}
<tr bgcolor="{cycle values="#eeeeee,#d0d0d0"}">
<td>{data}</td>
</tr>
{/section}
9{fetch file="/export/httpd/www.domain.com/docs/navbar.js"}
10 灵活地设置cache可以加速,设置config可以轻松定义不同界面风格 
到此为止,只欠一次全面查阅了!

[ 本帖最后由 iptton 于 2007-1-13 00:51 编辑 ]

iptton 发表于 2007-1-13 00:48

顺便发个dataGrid颜色分层 JS...


<table border=0 id="dd">
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
<tr><td>helosdfsfffffff</td></tr>
</table>
<script language="javascript">
function colorTable(tDOM,color1,color2,n){
   try{
      trArr=tDOM.getElementsByTagName("tr");
   }catch(e){
       alert("param tDOM isn't a DOM\n"+e+"\n"+typeof trArr);
       return;
   }
   if(n==undefined)n=trArr.length;
   if(color1==undefined)color1="#C1D8F0";
   if(color2==undefined)color2="#ffffff";
   var i=0;
   while(trArr!=undefined){
      trArr.style.background=(i%2?color1:color2);
      if(i>n)break;   
   }
}
d=document.getElementById("dd");
colorTable(d,"#c1d8f0","#ffffff");
</script>

hjack 发表于 2007-1-14 23:02

建议放在项目的目录下.
页: [1]
查看完整版本: smarty&SO ON学习笔记 (不发新帖了...网页相关的都发这来)