简体   繁体   English

在 Smarty tpl 中包含 PHP 文件

[英]Include PHP File in Smarty tpl

I want to include a PHP script that outputs some HTML in productdetail-full.tpl file (Smarty / Prestashop 1.6.x)我想在 productdetail-full.tpl 文件(Smarty / Prestashop 1.6.x)中包含一个输出一些 HTML 的 PHP 脚本

I tried:我试过:

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

AND

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

But they are both deprecated.但它们都已弃用。 Any suggestions?有什么建议?

Thanks!谢谢!

You should use SmartyBC - Backwards Compatibility Wrapper for this since it's not recommended using php code in the templates.您应该SmartyBC - Backwards Compatibility Wrapper使用SmartyBC - Backwards Compatibility Wrapper ,因为不建议在模板中使用 php 代码。

Instead of:代替:

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

Use:用:

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

And you will be able to use PHP in your Smarty template files.您将能够在 Smarty 模板文件中使用 PHP。

More info about this here:关于这里的更多信息:

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

Prestashop is a modular system that uses hooks to display information. Prestashop 是一个模块化系统,它使用钩子来显示信息。

According to Prestashop standards and solutions, you should use hooks and module:根据 Prestashop 标准和解决方案,您应该使用钩子和模块:

  1. Generate new module with a custom hook (or Use the available hook in the Productdetail-full.tpl file)使用自定义钩子生成新模块(或使用 Productdetail-full.tpl 文件中的可用钩子)
  2. Get content of your PHP file in your module (using curl for example)获取模块中 PHP 文件的内容(例如使用 curl)
  3. Pass your content to smarty将您的内容传递给 smarty
  4. display content in your Hook在你的 Hook 中显示内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM