PHP在html -模板文件- Smarty引擎


PHP in HTML-Template file - Smarty Engine

我现在使用的是Smarty PHP引擎。现在我想在模板文件中添加一些php代码,如下所示:

{php}echo "asdf";{/php}

但是当我打开浏览器时出现这个错误:

致命错误:未捕获异常'SmartyCompilerException'伴有消息'模板中语法错误'

有什么问题,我该如何解决?

{php}echo("Hello, world!");{/php}

也许这将工作代替?

{php}
// including a php script directly from the template.
include('/path/to/display_weather.php');
{/php}

这样你可以嵌入php代码到smarty模板文件。查看此参考http://www.smarty.net/docsv2/en/language.function.php.tpl