Default Variable Handling

默认变量处理

If a variable is used frequently throughout your templates, applying the default modifier every time it is mentioned can get a bit ugly. You can remedy this by assigning the variable its default value with the assign function.

如果一个变量在你的整个模板里被经常使用,而当你每次要用到这个变量的时候就给它赋默认的值,那将是无法忍受的。你可以通过使用 assign[赋值]这个函数来给这个变量赋上它的默认值来你补救。

Example 18-2. Assigning a template variable its default value

例 18-2.赋给一个模板变量默认的值

{* do this somewhere at the top of your template *}
{assign var="title" value=$title|default:"no title"}

{* if $title was empty, it now contains the value "no title" when you print it *}
{$title}