speed-providing-uncl Posted February 27, 2018 Share Posted February 27, 2018 (edited) Hi everyone, With PS 1.7, I could override an admin template located under /template/controllers, but I'm unable to override a template located just under /template/* Example: To override the Backoffice customer view, located in /admin-dev/themes/default/template/controllers/customers/helpers/view/view.tpl, I created /override/controllers/admin/templates/customers/helpers/view/view.tpl which is working fine! But how to override /admin-dev/themes/default/template/header.tpl? I tried /override/controllers/admin/templates/header.tpl but it's not working Thanks! Florian Edit: tuto is in second post Edited March 3, 2018 by Florian (see edit history) Link to comment Share on other sites More sharing options...
speed-providing-uncl Posted March 3, 2018 Author Share Posted March 3, 2018 I finally found out... Prestashop let you override its templates at only 1 condition, you have to re-order smarty template dirs : Because Smarty uses this as template dirs: array:2 [▼ 0 => "/admin-dev/themes/default/template/" 1 => "/override/controllers/admin/templates/" ] So it will first look for the template in /admin-dev, then in /override... We have to reverse that order! /override/classes/AdminController class AdminController extends AdminControllerCore protected function smartyOutputContent($content){ $smarty = $this->context->smarty; // at first, when given 'header.tpl' PS will look in $smarty->getTemplateDir(), which contains: // 0 => /admin-dev/themes/default/template/header.tpl // 1 => /override/controllers/admin/templates/header.tpl if the above is not found, which is never the case... // we have to reverse this order: $smarty->setTemplateDir( array_reverse($smarty->getTemplateDir()) ); // now it's reversed, look again for header.tpl and footer.tpl $smarty->assign([ 'header' => $smarty->fetch('header.tpl'), 'footer' => $smarty->fetch('footer.tpl'), ]); // then parent:: will look for 'layout.tpl' return parent::smartyOutputContent($content); } I copied/pasted /admin-dev/themes/default/template/layout.tpl+header.tpl to /override/controllers/admin/templates/layout.tpl+header.tpl and created /override/controllers/admin/templates/nav.tpl as an empty file, result below, no more nav for example, see attached screenshots. Or no more PrestaShop logo in top-left corner. DISCLAIMER: Symfony-powered pages are not working anymore... (Products + modules) and give the following error: Twig_Error_Runtime in layout.html.twig line 34: An exception has been thrown during the rendering of a template ("Unable to load template file 'search_form.tpl' in 'header.tpl'"). Link to comment Share on other sites More sharing options...
Mediaphag Posted October 23, 2018 Share Posted October 23, 2018 (edited) Dear friend! How can I compose the override for code in 1.6 ? Florian, I will be glad for your help. Edited October 23, 2018 by Mediaphag (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now