簡體   English   中英

在 Smarty tpl 中包含 PHP 文件

[英]Include PHP File in Smarty tpl

我想在 productdetail-full.tpl 文件(Smarty / Prestashop 1.6.x)中包含一個輸出一些 HTML 的 PHP 腳本

我試過:

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

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

但它們都已棄用。 有什么建議?

謝謝!

您應該SmartyBC - Backwards Compatibility Wrapper使用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 中顯示內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM