default[默认值]

Parameter PositionTypeRequiredDefaultDescription
1stringNoemptyThis is the default value to output if the variable is empty.
这是变量为空的时候的默认输出。

This is used to set a default value for a variable. If the variable is empty or unset, the given default value is printed instead. Default takes one argument.
为空变量设置一个默认值。
当变量为空或者未分配的时候,将由给定的默认值替代输出。

Example 5-10. default

index.php:

$smarty = new Smarty;
$smarty->assign('articleTitle', 'Dealers Will Hear Car Talk at Noon.');
$smarty->display('index.tpl');

index.tpl:

{$articleTitle|default:"no title"}
{$myTitle|default:"no title"}

OUTPUT:

Dealers Will Hear Car Talk at Noon.
no title