2010-04-19 63 views
2

我被要求在這個php/smarty頁面中包含一些html代碼片段。在付款之前,它基本上是一個概覽頁面末尾的銷售協議。如何在php/smarty中包含靜態html

將靜態html包含到我的php/smarty模板中的代碼是什麼?

謝謝...

回答

4

你的意思是包含一個包含靜態HTML的文件嗎?

{include file="htmlfile.html"}

編輯

由於文件僅僅是HTML,它可能是更好地使用{fetch},例如

{fetch file="path/to/html/file.html"} 

For local files, either a full system file path must be given, or a path relative to the executed php script.

+0

這就是我的意思。但它返回這個:'警告:Smarty錯誤:無法讀取資源:「custom:betalingsvilkar.html」in /home/euroworkerno/www/library/smarty/libs/Smarty.php on line 1095' – Kyle 2010-04-19 10:53:08

+0

'function trigger_error($ error_msg,$ error_type = E_USER_WARNING) { trigger_error(「Smarty error:$ error_msg」,$ error_type); }'這就是行1095. – Kyle 2010-04-19 10:57:02

1

如果你想包括包含JavaScript或類似的一些代碼,你可以使用 {literal}{/literal}標籤 到inlude你可以使用{include file="htmlfile.html"}湯姆說一個文件。

1

之前顯示模板,在PHP文件試試這個:

$smarty->assign('Sectionfile','section-name.html'); 
$smarty->display('template.tpl'); 
在模板本身

{include file="html_dir/$Sectionfile"} 
+0

致命錯誤:調用成員函數assign()on /home/euroworkerno/www/application/controller/CheckoutController.php on 1354行中的非對象 – Kyle 2010-04-19 11:02:05

+0

這是我在添加'$ smarty-> assign('Sectionfile','betalingsvilkar.html'); $ smarty-> display('completeOverview.tpl');' - 我的php/smarty很爛。 – Kyle 2010-04-19 11:02:31

2

像任何其他模板,Smarty的文件是HTML文件本身。你可以將你的HTML粘貼到smarty模板中。

+0

是的,這是我第一個需要完成的解決方案,在我的視角中也是最好的,因爲這個文件只包含在一個頁面中,但我的老闆堅持要把它作爲一個包含。 – Kyle 2010-04-19 11:03:44

相關問題