在Smarty tpl中包含PHP文件

问题描述 投票:0回答:2

[我想在productdetail-full.tpl文件(Smarty / Prestashop 1.6.x)中包括一个输出一些HTML的PHP​​脚本

我尝试过:

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

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

但是它们都已弃用。有什么建议吗?

谢谢!

php include prestashop smarty prestashop-1.6
2个回答
1
投票

您应该为此使用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


0
投票

Prestashop是使用钩子显示信息的模块化系统。

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

  1. 使用自定义挂钩生成新模块(或使用Productdetail-full.tpl文件中的可用挂钩)
  2. 在模块中获取PHP文件的内容(例如,使用curl)
  3. 将您的内容传递给聪明的人
  4. 在挂钩中显示内容
© www.soinside.com 2019 - 2024. All rights reserved.