Name
templateExists() 鈥 妫鏌ユā鏉挎槸鍚﹀瓨鍦
璇存槑
bool聽templateExists(string聽template);
妫鏌ョ殑妯℃澘鍙互鎸囧畾鏂囦欢璺緞锛屾垨鑰呬竴涓ā鏉胯祫婧愩
Example聽14.48.聽templateExists()
涓嬮潰渚嬪瓙浣跨敤$_GET['page']
鏉{include}
鎸囧畾鐨勬ā鏉裤
濡傛灉妯℃澘涓嶅瓨鍦紝鍒欎細鏄剧ず涓涓減age 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>
鐒跺悗鍦≒HP鑴氭湰涓細
<?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'); ?>