跳至内容

特性

大部分标签,都接受属性来指定或修改它们的行为。Smarty 函数的属性非常类似 HTML 属性。静态值不需要用引号括起来,但对于文本字符串则需要。带有或不带有修饰符的变量也可以使用,并且不应该放在引号中。您甚至可以使用 PHP 函数结果、插件结果和复杂表达式。

某些属性需要布尔值 (TRUE 或 FALSE)。它们可以指定为 truefalse。如果属性没有指定值,它将获得默认布尔值为 true。

示例

{include file="header.tpl"}

{include file="header.tpl" nocache}  // is equivalent to nocache=true

{include file="header.tpl" attrib_name="attrib value"}

{include file=$includeFile}

{include file=#includeFile# title="My Title"}

{assign var=foo value={counter}}  // plugin result

{assign var=foo value=substr($bar,2,5)}  // PHP function result

{assign var=foo value=$bar|strlen}  // using modifier

{assign var=foo value=$buh+$bar|strlen}  // more complex expression

{html_select_date display_days=true}

{mailto address="smarty@example.com"}

<select name="company_id">
  {html_options options=$companies selected=$company_id}
</select>

注意

尽管 Smarty 可以处理一些非常复杂的表达式和语法,但一个好习惯是使模板语法最小化,并专注于呈现。如果您发现自己的模板语法变得过于复杂,那么最好通过插件或修饰符将不直接处理呈现的部分移动到 PHP 中。