メインコンテンツまでスキップ
Version: Fegg 5.x

Assign

テンプレートで変数を設定します

説明​

{{ assign $var = expression }}
{{ assign $var.key = expression }}

テンプレート変数に、PHPの式の値を設定します。式にはテンプレート変数($page.title)、文字列リテラル、演算子、PHPの関数を使えますが、}は含められません。このタグは何も出力しません。

設定されていない変数は、式の中では警告なしにnullとして読まれます。

よくある使い方は、{{ transclude }}の前にサイト情報($site)を変えて、親レイアウトに新しい値を使わせることです。

例​

htdocs/_fegg/site/template/main/tpl/about.tpl
{{ assign $site.title = 'About | ' . $site.title }}
{{ transclude '/template/siteframe' }}

{{ section contents }}
{{ assign $format = 'Y/m/d' }}
<p>{{ $page.updated|feggDate:$format }}</p>
{{ end section contents }}
htdocs/_fegg/site/template/main/tpl/template/siteframe.tpl
<title>{{ $site.title }}</title>
Output
<title>About | Example Inc.</title>
メモ

レイアウトが読む値($site.titleなど)は、テンプレートの最上位で設定します。{{ section }}の中で設定すると、そのセクションの中でしか変わりません(Transcludeを参照)。