在Smarty tpl中包含PHP文件



我想在productdetail-full.tpl文件(Smarty/Prestashop 1.6.x(中包含一个PHP脚本,用于输出一些HTML

我试过了:

{php}
include('show-stock-pos.php');
{/php}

{include_php 'show-stock-pos.php'}

但它们都遭到了抨击。有什么建议吗?

谢谢!

您应该使用SmartyBC - Backwards Compatibility Wrapper,因为不建议在模板中使用php代码。

代替:

require_once('path/to/smarty/libs/Smarty.class.php');
$smarty = new Smarty();

用途:

require_once('path/to/smarty/libs/SmartyBC.class.php');
$smarty = new SmartyBC();

您将能够在Smarty模板文件中使用PHP。

更多信息请点击此处:

https://www.smarty.net/docs/en/bc.tpl

Prestashop是一个模块化系统,它使用钩子来显示信息。

根据Prestashop标准和解决方案,您应该使用挂钩和模块:

  1. 使用自定义钩子生成新模块(或使用Productdetail-full.tpl文件中的可用钩子(
  2. 在模块中获取PHP文件的内容(例如使用curl(
  3. 将您的内容传递给smarty
  4. 在Hook中显示内容

最新更新