例 13-1. template_exists()
この例は、コンテンツテンプレートを
インクルード
するのに $_GET['page'] を使用しています。
テンプレートが存在しない場合、代わりにエラーページが表示されます。
まずは page_container.tpl から。
<html> <head><title>{$title}</title></head> <body> {include file='page_top.tpl'}
{* コンテンツページの中央部分をインクルード *} {include file=$content_template}
{include file='page_footer.tpl'} </body>
|
そしてスクリプトです。
<?php
// index.inc.tpl のようにファイル名をセットします $mid_template = $_GET['page'].'.inc.tpl';
if( !$smarty->template_exists($mid_template) ){ $mid_template = 'page_not_found.tpl'; } $smarty->assign('content_template', $mid_template);
$smarty->display('page_container.tpl');
?>
|