Jump to content

[TUTO] How to override admin header template


speed-providing-uncl

Recommended Posts

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 by Florian (see edit history)
Link to comment
Share on other sites

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'").

Capture d’écran 2018-03-02 à 22.06.03.png

Capture d’écran 2018-03-02 à 22.12.13.png

Link to comment
Share on other sites

  • 7 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...