閲嶈鎻愮ず
{include_php}鏄簾寮冪殑鍑芥暟锛岀敤娉ㄥ唽鎻掍欢鐨勬柟寮忔潵灏嗙▼搴忎唬鐮佸拰鏄剧ず鍒嗙锛屾槸鏇村ソ鐨勯夋嫨銆
鍦⊿marty 3.1锛{include_php}浠呭湪SmartyBC涓彲鐢.
| 鍙傛暟鍚嶇О | 绫诲瀷 | 蹇呴夊弬鏁 | 榛樿鍊 | 璇存槑 |
|---|---|---|---|---|
| file | string | Yes | n/a | 杞藉叆PHP鏂囦欢鐨勭粷瀵硅矾寰 |
| once | boolean | No | TRUE |
鏄惁浠呰浇鍏ヤ竴娆¤PHP鏂囦欢锛屽嵆浣垮娆℃墽琛屻 |
| assign | string | No | n/a | 灏嗗寘鍚枃浠剁殑杈撳嚭璧嬪肩粰鍙橀噺 |
鍙夋爣璁:
| 鍚嶇О | 璇存槑 |
|---|---|
| nocache | 鍏抽棴鍖呭惈PHP鏂囦欢鐨勭紦瀛 |
{include_php}鐢ㄤ簬杞藉叆涓涓狿HP鏂囦欢鍒版ā鏉夸腑銆
灞炴т腑鐨file璺緞鍙互鏄粷瀵硅矾寰勶紝鎴栨槸鐩稿浜
$trusted_dir鐨勮矾寰勩
濡傛灉瀹夊叏鏈哄埗寮鍚紝閭d箞鍙湁鍦$trusted_dir鐩綍涓殑鏂囦欢鎵嶅彲浠ヨ杞藉叆銆
鍙傝瀹夊叏鏈哄埗銆
榛樿鎯呭喌涓嬶紝璇HP鏂囦欢浠呬細杞藉叆涓娆★紝鍗充娇澶氭鎵ц妯℃澘銆
浣犲彲浠ヨ缃once灞炴т娇鍏舵瘡娆℃墽琛岄兘杞藉叆銆
褰搊nce璁剧疆涓FALSE锛孭HP鏂囦欢灏嗗湪姣忔妯℃澘鎵ц鐨勬椂鍊欓兘浼氳杞藉叆銆
浣犲彲浠ヨ缃彲閫夌殑灞炴assign锛屾潵灏{include_php}杞藉叆鐨勫唴瀹
璧嬪肩粰涓涓寚瀹氱殑妯℃澘鍙橀噺锛岃屼笉鏄緭鍑恒
鍦ㄨ浇鍏ョ殑PHP鏂囦欢涓紝鍙互閫氳繃$_smarty_tpl->smarty鏉ヨ幏鍙栧埌褰撳墠鐨凷marty瀵硅薄銆
Example聽7.55.聽 {include_php} 鍑芥暟
load_nav.php 鏂囦欢:
<?php
// load in variables from a mysql db and assign them to the template
require_once('database.class.php');
$db = new Db();
$db->query('select url, name from navigation order by name');
$this->assign('navigation', $db->getRows());
?>
妯℃澘锛
{* absolute path, or relative to $trusted_dir *}
{include_php file='/path/to/load_nav.php'}
{include_php '/path/to/load_nav.php'} {* short-hand *}
{foreach item='nav' from=$navigation}
<a href="{$nav.url}">{$nav.name}</a><br />
{/foreach}
