public function getCMSLink($cms, $alias = null, $ssl = null, $id_lang = null, $id_shop = null, $relative_protocol = false){
if (!$id_lang) {
$id_lang = Context::getContext()->language->id;
}
$url = $this->getBaseLink($id_shop, $ssl, $relative_protocol).$this->getLangLink($id_lang, null, $id_shop);
$dispatcher = Dispatcher::getInstance();
if (!is_object($cms)) {
if ($alias !== null && !$dispatcher->hasKeyword('cms_rule', $id_lang, 'meta_keywords', $id_shop) && !$dispatcher->hasKeyword('cms_rule', $id_lang, 'meta_title', $id_shop)) {
return $url.$dispatcher->createUrl('cms_rule', $id_lang, array('id' => (int)$cms, 'rewrite' => (string)$alias), $this->allow, '', $id_shop);
}
$cms = new CMS($cms, $id_lang);
}
// Set available keywords
$params = array();
$params['id'] = $cms->id;
$params['rewrite'] = (!$alias) ? (is_array($cms->link_rewrite) ? $cms->link_rewrite[(int)$id_lang] : $cms->link_rewrite) : $alias;
$category = new CMSCategory($cms->id_cms_category);
//Custom code to insert $category into SEO & URL section.
$params['category'] = (!is_null($category->name[1]) && !empty($category->name[1])) ? Tools::str2url($category->name[1]) : "";
$params['meta_keywords'] = '';
//end of custom code
if (isset($cms->meta_keywords) && !empty($cms->meta_keywords)) {
$params['meta_keywords'] = is_array($cms->meta_keywords) ? Tools::str2url($cms->meta_keywords[(int)$id_lang]) : Tools::str2url($cms->meta_keywords);
}
$params['meta_title'] = '';
if (isset($cms->meta_title) && !empty($cms->meta_title)) {
$params['meta_title'] = is_array($cms->meta_title) ? Tools::str2url($cms->meta_title[(int)$id_lang]) : Tools::str2url($cms->meta_title);
}
return $url.$dispatcher->createUrl('cms_rule', $id_lang, $params, $this->allow, '', $id_shop);
} Prestahop Admin Login Page — header.tpl
For those of you who are just looking to copy/paste click on the the complete code or scroll to the bottom of the article…whichever is faster o_O So here is the problem, currently I’m running Prestashop 1.6.1.6 in one of my client’s websites and they ask me to make some modifications to the login admin page. The login admin page is the one we use to login to the back-end of your Prestashop installation. So in my mind, this was easy all I need to do was to find the login admin template override it and apply the needed modifications; yes and no. The first thing I did was to find the template files for the login admin page located at /_ADMIN_DIR_/themes/default/template/controllers/login/. In this folder you will find 4 files (3 files really since we don’t care about the index.php):
- content.tpl
- header.tpl
- layout.tpl
- index.php(This one we don’t care about)
- Override AdminControllerCore class located in root/classes/controller/AdminController.php
- Find and override the display method — public function display()
- Now you can override your header.tpl located in the root/_ADMIN_DIR_/themes/default/template/controllers/login/header.tpl
1
First step is to locate the public function display() in the AdminController$dir = $this->context->smarty->getTemplateDir(0).'controllers'.DIRECTORY_SEPARATOR.trim($this->override_folder, '\\/').DIRECTORY_SEPARATOR;Now comment out or delete the following 2 lines of code:
$dir = $this->context->smarty->getTemplateDir(0).'controllers'.DIRECTORY_SEPARATOR.trim($this->override_folder, '\\/').DIRECTORY_SEPARATOR; $header_tpl = file_exists($dir.'header.tpl') ? $dir.'header.tpl' : 'header.tpl';Then replace those lines of code with the following:
$dir = $this->context->smarty->getTemplateDir(1).DIRECTORY_SEPARATOR.trim($this->override_folder, '\\/').DIRECTORY_SEPARATOR;
$dir_core = $this->context->smarty->getTemplateDir(0) .'controllers'.DIRECTORY_SEPARATOR.trim($this->override_folder, '\\/').DIRECTORY_SEPARATOR;
if(file_exists($dir.'header.tpl')){
$header_tpl = $dir.'header.tpl';
}elseif(file_exists($dir_core.'header.tpl')){
$header_tpl = $dir_core.'header.tpl';
}else{
$header_tpl = 'header.tpl';
}For those of you who are a little curious you can see that the footer and modules have the same problem as the header. Here it is, this is the final version of AdminController file located at<?php /** * 2007-2016 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2016 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminController extends AdminControllerCore{ /** * @return void * @throws Exception * @throws SmartyException */ public function display(){ $this->context->smarty->assign(array( 'display_header' => $this->display_header, 'display_header_javascript'=> $this->display_header_javascript, 'display_footer' => $this->display_footer, 'js_def' => Media::getJsDef(), )); // Use page title from meta_title if it has been set else from the breadcrumbs array if (!$this->meta_title) { $this->meta_title = $this->toolbar_title; } if (is_array($this->meta_title)) { $this->meta_title = strip_tags(implode(' '.Configuration::get('PS_NAVIGATION_PIPE').' ', $this->meta_title)); } $this->context->smarty->assign('meta_title', $this->meta_title); $template_dirs = $this->context->smarty->getTemplateDir(); //print_r($this->context->smarty->template_dir); // Check if header/footer have been overriden $dir = $this->context->smarty->getTemplateDir(1).DIRECTORY_SEPARATOR.trim($this->override_folder, '\\/').DIRECTORY_SEPARATOR; $dir_core = $this->context->smarty->getTemplateDir(0) .'controllers'.DIRECTORY_SEPARATOR.trim($this->override_folder, '\\/').DIRECTORY_SEPARATOR; if(file_exists($dir.'header.tpl')){ $header_tpl = $dir.'header.tpl'; }elseif(file_exists($dir_core.'header.tpl')){ $header_tpl = $dir_core.'header.tpl'; }else{ $header_tpl = 'header.tpl'; } $module_list_dir = $this->context->smarty->getTemplateDir(1).DIRECTORY_SEPARATOR.'modules_list'.DIRECTORY_SEPARATOR; $module_list_dir_core = $this->context->smarty->getTemplateDir(0).'helpers'.DIRECTORY_SEPARATOR.'modules_list'.DIRECTORY_SEPARATOR; //$header_tpl = file_exists($dir.'header.tpl') ? $dir.'header.tpl' : 'header.tpl'; //print_r($module_list_dir); if(file_exists($dir.'footer.tpl')){ $footer_tpl = $dir.'footer.tpl'; }elseif(file_exists($dir_core.'footer.tpl')){ $footer_tpl = $dir_core.'footer.tpl'; }else{ $footer_tpl = 'footer.tpl'; } //$footer_tpl = file_exists($dir.'footer.tpl') ? $dir.'footer.tpl' : 'footer.tpl'; if(file_exists($module_list_dir.'modal.tpl')){ $modal_module_list = $module_list_dir.'modal.tpl'; }elseif(file_exists($module_list_dir_core.'modal.tpl')){ $modal_module_list = $module_list_dir_core.'modal.tpl'; }else{ $modal_module_list = 'modal.tpl'; } // $modal_module_list = file_exists($module_list_dir.'modal.tpl') ? $module_list_dir.'modal.tpl' : 'modal.tpl'; $page_header_toolbar = file_exists($dir.'page_header_toolbar.tpl') ? $dir.'page_header_toolbar.tpl' : 'page_header_toolbar.tpl'; $tpl_action = $this->tpl_folder.$this->display.'.tpl'; // Check if action template has been overriden foreach ($template_dirs as $template_dir) { if (file_exists($template_dir.DIRECTORY_SEPARATOR.$tpl_action) && $this->display != 'view' && $this->display != 'options') { if (method_exists($this, $this->display.Tools::toCamelCase($this->className))) { $this->{$this->display.Tools::toCamelCase($this->className)}(); } $this->context->smarty->assign('content', $this->context->smarty->fetch($tpl_action)); break; } } if (!$this->ajax) { $template = $this->createTemplate($this->template); $page = $template->fetch(); } else { $page = $this->content; } if ($conf = Tools::getValue('conf')) { $this->context->smarty->assign('conf', $this->json ? Tools::jsonEncode($this->_conf[(int)$conf]) : $this->_conf[(int)$conf]); } foreach (array('errors', 'warnings', 'informations', 'confirmations') as $type) { if (!is_array($this->$type)) { $this->$type = (array)$this->$type; } $this->context->smarty->assign($type, $this->json ? Tools::jsonEncode(array_unique($this->$type)) : array_unique($this->$type)); } if ($this->show_page_header_toolbar && !$this->lite_display) { $this->context->smarty->assign( array( 'page_header_toolbar' => $this->context->smarty->fetch($page_header_toolbar), 'modal_module_list' => $this->context->smarty->fetch($modal_module_list), ) ); } $this->context->smarty->assign( array( 'page' => $this->json ? Tools::jsonEncode($page) : $page, 'header' => $this->context->smarty->fetch($header_tpl), 'footer' => $this->context->smarty->fetch($footer_tpl), ) ); $this->smartyOutputContent($this->layout); } }