日历

« 2008-08-30  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

RSS订阅

内建函数

2007-04-19 16:28:27 / 天气: 晴朗 / 心情: 高兴 / 个人分类:smart学习

[ ]非必需(not required)

1.config_load
{config_load file="" [section] [scope] [global]}
这个函数加载配置文件到模板的变量里
file string 要包含进来的配置文件名称 必需
section string 要加载的部分的名称
scope string 被处理的变量的作用域.必须是local,parent或者global.
              local的意思是变量将在本模板里被加载.
              parent 的意思是变量将在本模板和上级模板被加载.
              global的意思是变量将应用到所有的模板.
global boolean 变量是否在上级模板可视,和 scope=parent相同

2.foreach,foreachelse
{foreach from=$ item=  [key=]  [name=]}
foreach的标签必须成对,必须的参数是from和item
from string 需要循环的数组的名称 
item string 当前元素的变量名
key string 当前关键字的变量名
name string 访问foreache属性的foreach循环名
{* The key contains the key for each looped value

assignment looks like this:

$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
      array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));

*}

{foreach name=outer item=contact from=$contacts}
  {foreach key=key item=item from=$contact}
    {$key}: {$item}<br>
  {/foreach}
{/foreach}

OUTPUT:

phone: 1<br>
fax: 2<br>
cell: 3<br>
phone: 555-4444<br>
fax: 555-3333<br>
cell: 760-1234<br>
 
3.include
{include file="header.tpl"}
Include tags are used for including other templates in the current template.

4.include_php
用于加载PHP文件include_php tags are used to include a php scrīpt in your template

5insert
Insert tags work much like include tags, except that insert tags are not cached when you have template caching enabled. They will be executed on every invocation of the template

6if,elseif,else
if statements in Smarty have much the same flexibility as php if statements, with a few added features for the template engine. Every if must be paired with an /if.
smart中的IF语句有着和PHP中的差不多的弹性,除了必须加上/if
{if $name eq "Fred"}
 Welcome Sir.
{elseif $name eq "Wilma"}
 Welcome Ma'am.
{else}
 Welcome, whatever you are.
{/if}

7.ldelim,rdelim

 

 

 

 


 


相关阅读:

TAG: smart学习

Open Toolbar