Get Smarty

Donate

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

Buy cheap glasses from Cheapglasses123.com and save up to 80%.

Where to buy prescription glasses? EyewearCanada.com is your best choice!

Visit www.sport-kick.com for cheap soccer cleats, sneakers and Soccer Jerseys updates

Advertisement

Name

templateExists() — 检查模板是否存在

说明

bool templateExists(string template);

检查的模板可以指定文件路径,或者一个模板资源。

Example 14.48. templateExists()

下面例子使用$_GET['page']{include}指定的模板。 如果模板不存在,则会显示一个“page not found”的错误信息。 首先是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脚本中:


<?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