Get Smarty

Donate

Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Advertisement

変数のデフォルトの扱い

変数がテンプレートの至る所に頻繁に使われる場合、それが記述されるたびに変更子 default を用いると少し見苦しくなりがちです。この場合、 {assign} 関数によって変数にデフォルト値を割り当てる事でこれを改善する事ができます。

Example 18.2. デフォルト値をテンプレート変数に割り当てる


{* これをテンプレートのトップのどこかに記述します *}
{assign var='title' value=$title|default:'no title'}

{* $titleが空白ならば、それを出力する時に"no title"の値を含めます *}
{$title}

    

default 修飾子および 空白の変数の扱い も参照してください。

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors