medk
medk

Reputation: 9549

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)

I tried:

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

AND

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

But they are both deprecated. Any suggestions?

Thanks!

Upvotes: 0

Views: 2394

Answers (2)

Mahdi Shad
Mahdi Shad

Reputation: 1457

Prestashop is a modular system that uses hooks to display information.

According to Prestashop standards and solutions, you should use hooks and module:

  1. Generate new module with a custom hook (or Use the available hook in the Productdetail-full.tpl file)
  2. Get content of your PHP file in your module (using curl for example)
  3. Pass your content to smarty
  4. display content in your Hook

Upvotes: 0

jeprubio
jeprubio

Reputation: 18022

You should use SmartyBC - Backwards Compatibility Wrapper for this since it's not recommended using php code in the templates.

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.

More info about this here:

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

Upvotes: 2

Related Questions