例 18-3. ヘッダテンプレートにタイトルの変数を渡す
mainpage.tpl - メインページを描画する際に、
"Main Page" というタイトルを
header.tpl に私、それをタイトルとして使用します。
{include file='header.tpl' title='Main Page'}
{* ここにテンプレートの本体を記述します *}
{include file='footer.tpl'} |
archives.tpl - アーカイブページを描画する際には、
タイトルは "Archives" となります。
この例では、ハードコーディングされた変数ではなく
archives_page.conf
から変数を取得していることに注意しましょう。
{config_load file='archive_page.conf'}
{include file='header.tpl' title=#archivePageTitle#}
{* ここにテンプレートの本体を記述します *}
{include file='footer.tpl'} |
header.tpl - $title 変数が設定されていない場合に、
"Smarty News" と表示します。これは
default
修飾子を使用して実現しています。
<html>
<head>
<title>{$title|default:'Smarty News'}</title>
</head>
<body> |
footer.tpl