我剛開始使用smarty。我只是有點混淆如何將文件聯合在一起。簡單地說,我想加入的頁眉和頁腳中的其他文件,如指數和發佈在smarty中包含頁眉和頁腳文件的最佳方法
所以我創建了一個header.php文件,header.tpl並添加下面的代碼的header.php
$header_template = new Smarty;
$header_template->debugging = false;
$header_template->caching = false;
$header_template->setTemplateDir('./templates/');
$header_template->assign("title", $home_title);
$header_template->assign("description", $output_cities);
$header_template->display('header.tpl');
然後我創建了一個index.php和index.tpl文件,並在索引中。 PHP添加以下代碼
include('header.php');
$index_template = new Smarty;
$index_template->debugging = false;
$index_template->caching = false;
$index_template->setTemplateDir('./templates/');
$index_template->assign("posts", $post);
$index_template->display('index.tpl');
但智者文檔中,他們要求使用{include file=header.tpl'}
所以我不知道我是否以正確的方式做這個。感謝您能給我的任何答案。
有趣的錯字在你的第一個字... – JustOnUnderMillions
@JustOnUnderMillions哈哈我的壞。抱歉。 – Jordyn
基本上,當使用Smarty的時候,你不應該用include('header.php')包含頁面的一部分,',在模板中做所有的工作,當它關於組合模板 – JustOnUnderMillions