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

Name

templateExists() — 指定したテンプレートが存在するかどうかをチェックします。

説明

bool templateExists(string template);

ファイルシステムに関するテンプレートへのパス 又はテンプレートを指定するリソースの文字列のいずれかを受け入れる事ができます。

Example 13.32. templateExists()

この例は、コンテンツテンプレートを インクルード するのに $_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->templateExists($mid_template) ){
    $mid_template = 'page_not_found.tpl';
}
$smarty->assign('content_template', $mid_template);

$smarty->display('page_container.tpl');

?>

  

display()fetch(){include} および {insert} も参照してください。

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors