i'm learning addon developer prestashop. have been trying solve long time, how override template file module? @ moment i'm overriding entire file copying template file in override folder module on installation:
from:
/modules/<module>/views/templates/admin/products/informations.tpl
to:
/override/controllers/admin/templates/products/informations.tpl
overriding whole file add input field seems pretty rough.
this works fine, i'm worried because if user installs other module wants use same file , corrupts or prestashop's new version changes file , doesn't support new version anymore. in every way feels dirty solution problem.
is there way override part of file , maybe directly module folder? there better way this? how do this?
to override templates in prestashop need override hookdisplayoverridetemplate
method modules controller.
to register hook, add install function:
$this->registerhook('displayoverridetemplate');
now add own version of function server .tpl file.
public function hookdisplayoverridetemplate($params) { $controllername = get_class($params['controller']); $tpl = dirname(__file__) . '/views/templates/override/example.tpl'; if ($controllername == 'examplecontroller' && file_exists($tpl)) return $tpl; return false; }
in example, need place template want override inside modules /views/template/override
folder.
when page loaded front controller, classes/controller/frontcontroller.php
, calls hookdisplayoverridetemplate
function , if template returned, loaded, otherwise loads default template.
i have tested , know works prestashop v1.5 , v1.6
Comments
Post a Comment