how to override tpl module in prestashop 1.7.1.1

筅森魡賤 提交于 2019-12-13 01:53:56

问题


im trying to override the tpl of ps_categorytree module, but it didn't work i tried to put the file under override like this:

override/themes/laber_ethan_home5/modules/ps_categorytree/views/templates/hook/ps_categorytree.tpl

-im using prestashop 1.7.1.1 and i bought a theme.

Help please!


回答1:


you don't need to put this in override folder, simply use the modules folder that is in the active theme. The correct way to put your tpl file is:

/themes/laber_ethan_home5/modules/ps_categorytree/views/templates/hook/ps_categorytree.tpl

Hope it helps you, bye.




回答2:


I wanted to add tpl from my module to theme so that my version of tpl will override the Prestashop but I found all stating that to create the same directory structure in the module that consists of theme name but theme name can change easily so did it in a different way

in my case, the file was included form path

classes\pdf\HTMLTemplate.php

so I override it from my module

modules\module_name\override\classes\pdf\HTMLTemplate.php

and override method

protected function getTemplate($template_name) {
    $template = false;
    $default_template = rtrim(_PS_PDF_DIR_, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $template_name . '.tpl';
    $overridden_template = _PS_ALL_THEMES_DIR_ . $this->shop->getTheme() . DIRECTORY_SEPARATOR . 'pdf' . DIRECTORY_SEPARATOR . $template_name . '.tpl';
    $module_template = _PS_MODULE_DIR_ . $template_name;
    if (file_exists($module_template)) {
        $template = $module_template;
    } else if (file_exists($overridden_template)) {
        $template = $overridden_template;
    } elseif (file_exists($default_template)) {
        $template = $default_template;
    }
    return $template;
}

See

$module_template = _PS_MODULE_DIR_ . $template_name;

similarly, you can do it.



来源:https://stackoverflow.com/questions/46035990/how-to-override-tpl-module-in-prestashop-1-7-1-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!