日历

« 2008-07-25  
  12345
6789101112
13141516171819
20212223242526
2728293031  

RSS订阅

  • 数据库

    2007-04-19 16:32:29

  • 内建函数

    2007-04-19 16:28:27

    [ ]非必需(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

     

     

     

     


     

  • 变量调节器

    2007-04-19 16:27:36

    {* Truncate the topic to 40 characters use ... at the end *}
    {* 取其前40个字符 *}
    Topic: {$topic|truncate:40:"..."}

    {$articleTitle}计算变量里的字符数
    {$articleTitle|count_characters}

    字符串连接
    $smarty->assign('articleTitle', 'Psychics predict world didn't end');
    {$articleTitle|cat:" yesterday."}
    Psychics predict world didn't end yesterday.

    计算变量里句子的数量
    {$articleTitle|count_sentences}

    计算变量里的词数
    {$articleTitle}
    {$articleTitle|count_words}

    lower 小写
    {$articleTitle}
    {$articleTitle|lower}
    OUTPUT:
    Two Convicts Evade Noose, Jury Hung.
    two convicts evade noose, jury hung.

    upper 大写  将变量改为大写

    capitalize 首字大写
    {$articleTitle}
    {$articleTitle|capitalize}
    OUTPUT:
    Police begin campaign to rundown jaywalkers.
    Police Begin Campaign To Rundown Jaywalkers
     
    nl2br
    换行符替换成<br />
    {$articleTitle|nl2br}
    $smarty->assign('articleTitle', "Sun or rain expected\ntoday, dark tonight");
    Sun or rain expected<br />today, dark tonight

    replace 替换
    $smarty->assign('articleTitle', "Child's Stool Great for Use in Garden.");
    {$articleTitle|replace:"Garden":"Vineyard"}
    Child's Stool Great for Use in Vineyard.

    spacify 插空 是一种在字符串的每个字符之间插入空格或者其他的字符(串).
    $smarty->assign('articleTitle', 'Something Went Wrong in Jet Crash, Experts Say.');
    {$articleTitle|spacify:"^^"}
    s^^o^^m^^e^^t^^h^^i^^n^^g^^ ^^W^^e^^n^^t^^ ^^W^^r^^o^^n^^g^^ ^^i^^n^^ ^^J^^e^^t^^ ^^C^^r^^a^^s^^h^^,^^ ^^E^^x^^p^^e^^r^^t^^s^^ ^^S^^a^^y^^.

    string_format 字符串格式化 是一种格式化浮点数的方法.例如十进制数.使用sprintf语法格式化
    $smarty->assign('number', 23.5787446);
    {$number|string_format:"%.2f"}
    {$number|string_format:"%d"}
    23.58
    24

    strip去除(多余空格) 替换所有重复的空格,换行和tab为单个
    $smarty->assign('articleTitle', "Grandmother of\neight makes\t    hole in one.");
    {$articleTitle|strip}
    {$articleTitle|strip:"&nbsp;"}
    Grandmother of eight makes hole in one.
    Grandmother&nbsp;of&nbsp;eight&nbsp;makes&nbsp;hole&nbsp;in&nbsp;one

    strip_tags 去除html标签  去除在<和>之间的所有标签,包括<和>.
    $smarty->assign('articleTitle', "Blind Woman Gets <font face=\"helvetica\">New Kidney</font> from Dad she Hasn't Seen in <b>years</b>.");
    {$articleTitle|strip_tags}
    Blind Woman Gets New Kidney from Dad she Hasn't Seen in years.

     

    eq equal ==
    ne not equal !=
    cmp compare <=>
    lt less than <
    gt greater than>

     

     

     

     

     


     

Open Toolbar