Skip to content

Instantly share code, notes, and snippets.

@PrestaEdit
Last active October 21, 2016 05:20
Show Gist options
  • Save PrestaEdit/4ea5fbd7a9fe0ae69909b984f11eda3a to your computer and use it in GitHub Desktop.
Save PrestaEdit/4ea5fbd7a9fe0ae69909b984f11eda3a to your computer and use it in GitHub Desktop.
renderWidget / Use hookName as template source
<?php
/*
* [...]
*/
use PrestaShop\PrestaShop\Adapter\Cart\CartPresenter;
if (!defined('_PS_VERSION_'))
exit;
use PrestaShop\PrestaShop\Core\Module\WidgetInterface;
class Ps_Shoppingcart extends Module implements WidgetInterface
{
[...]
public function getWidgetVariables($hookName, array $params)
{
[...]
}
public function renderWidget($hookName, array $params)
{
if (Configuration::isCatalogMode()) {
return;
}
$this->smarty->assign($this->getWidgetVariables($hookName, $params));
$tplName = $hookName.'.tpl';
$template_path = $this->getTemplatePath($tplName);
if ($template_path !== null) {
return $this->fetch('module:ps_shoppingcart/'.$tplName);
}
return $this->fetch('module:ps_shoppingcart/ps_shoppingcart.tpl');
}
}
@julienbourdeau
Copy link

julienbourdeau commented Oct 21, 2016

$this->getTemplatePath($tplName); was kept for backward compatibility. It's shouldn't be used with Smarty module resources ($this->fetch('module:ps_shoppingcart/xxx)) beacuse it will give you a full path.

You should implement your own method getModuleTemplatePath which check theme override, parent theme override and then module template :(

See https://github.com/PrestaShop/PrestaShop/blob/develop/classes/module/Module.php#L2306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment