23 January 2011

use include in tpl files with smarty in prestashop modules

The smarty version included in prestashop seems to be slightly different than the offical release.

If you want to use the include instruction in a tpl file, you have to be aware of these limitations inside the instruction:
  • you cannot concat strings
  • you must use full path
One easy way I've found to achieve this is to use the following code in your .php file:
// Get the full path of the mytpl template
$smarty->assign('one_var', dirname(__FILE__).'/mytpl.tpl');
return $this->display(__FILE__, $this->name.'.tpl');
And the following code in your .tpl file:
{include file=$one_var}

No comments: