Functions

Each Smarty tag either prints a variable or invokes some sort of function. Functions are processed and displayed by enclosing the function and its attributes into delimiters like so: {funcname attr1="val" attr2="val"}.

每個 Smarty 標籤可以是 變數 或是引用函式。函式可以先處理然後將處理結果放在標籤圍起來的區塊中,函式的使用方式如 後:{funcname attr1="val" attr2="val"}。

Example 3-3. 函式語法

{config_load file="colors.conf"}

{include file="header.tpl"}

{if $highlight_name}
    Welcome, <font color="{#fontColor#}">{$name}!</font>
{else}
    Welcome, {$name}!
{/if}

{include file="footer.tpl"}

Both built-in functions and custom functions have the same syntax in the templates. Built-in functions are the inner workings of Smarty, such as if, section and strip. They cannot be modified. Custom functions are additional functions implemented via plugins. They can be modified to your liking, or you can add new ones. html_options and html_select_date are examples of custom functions.

在樣版中內建函式與客制函式兩者都是用相同的語法,內建函式是 Smarty 內部運作的 函式,如 if, sectionstrip,這些函式是不能再被修改的。客制函式是用外掛的方式所新增的函式,可以照你自己的意思 加以修改或新增。html_optionshtml_select_date 都是客制函式的範例。