[英]Smarty: how to include php in template?
我試過{include_php file="phpfile.php"}
和{php}
標記,但都導致不推薦使用的錯誤。 你不能再在 Smarty 中這樣做嗎? 我在文檔中找不到任何內容。
我繞過了這個問題。 創建一個名為block.php_code.php
的插件文件,其中包含此 function:
function smarty_block_php_code($params, $content, &$smarty)
{
if (is_null($content))
{
return;
}
if ('<?php' == substr($content,0,5) && '?>' == substr($content, -2))
$content = substr($content,5,-2);
ob_start();
eval($content);
return ob_get_clean();
}
在您的模板中,您可以編寫:
{php_code}{literal}<?php
print "Hello, world!";
?>{/literal}{/php_code}
{include_php} 在 Smarty2 和 3 中都被標記為已棄用; {php} 僅在 Smarty3 中:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.