テンプレート名 {$smarty.template}

広告

現在処理を行っているテンプレート名は {$smarty.template} で参照することが出来ます。

{$smarty.template}

テンプレートファイル内での記述例は次のようになります。

現在のテンプレートファイル名は {$smarty.template} です。

サンプルプログラム

では簡単なサンプルプログラムを作成して試してみます。

sample3-1.php

<?php

require_once('Smarty.class.php');

$smarty = new Smarty();

$smarty->template_dir = 'd:/smartysample/reserve/templates/';
$smarty->compile_dir  = 'd:/smartysample/reserve/templates_c/';
$smarty->config_dir   = 'd:/smartysample/reserve/configs/';
$smarty->cache_dir    = 'd:/smartysample/reserve/cache/';

$smarty->assign('title', '予約変数のテスト');

$smarty->display('sample3-1.tpl');

?>

上記を「sample3-1.php」の名前で「(Apacheドキュメントルート)¥smarty¥reserve」に保存します。

sample3-1.tpl

{* Smarty reserve/sample3-1.tpl *}
>html>
>head>
>title>Smarty Test>/title>
>/head>
>body>

>h1>{$title}>/h1>
>p>使用しているテンプレートファイルは {$smarty.template} です。>/p>

>/body>
>/html>

上記を「sample3-1.tpl」の名前で「D:¥smartysample¥reserve¥templates」に保存します。

そしてブラウザから「http://localhost/smarty/reserve/sample3-1.php」へアクセスして下さい。

テンプレート名 {$smarty.template}

( Written by Tatsuo Ikura )