Every Prestashop store owner works with a back-office daily. In 1.5 version it became very user-friendly and easy to use. But how exactly does it work? This article is about initialization, files location and main templates of Presta admin panel.
1. Initialization in a controller
In a controller we are accustomed to see the code that is similar to this:
1 2 3 4 5 6 7 8 9 10 11 12 |
public function displayAjax() { if ($this->json) { $this->context->smarty->assign(array( 'json' => true, 'status' => $this->status, )); } $this->layout = 'layout-ajax.tpl'; //indicate template file return $this->display(); } |
Let’s demonstrate and explain the code of the AdminCоntrоller: :display() method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
public function display() { // display_header и display_footer – these flags indicate whether footer and header should be generated or not. In our case the Ajax method and these elements are not important. $this->context->smarty->assign(array( 'display_header' => $this->display_header, 'display_footer' => $this->display_footer, ) ); // Use page title from meta_title if it has been set else from the breadcrumbs array if (!$this->meta_title) $this->meta_title = isset($this->breadcrumbs[1]) ? $this->breadcrumbs[1] : $this->breadcrumbs[0]; $this->context->smarty->assign('meta_title', $this->meta_title); $tpl_action = $this->tpl_folder.$this->display.'.tpl'; // Check if action template has been override foreach ($this->context->smarty->getTemplateDir() 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; } //the fetch method converts template into html if (!$this->ajax) { $template = $this->createTemplate($this->template); $page = $template->fetch(); } else $page = $this->content; //the controller will be available in smarty if the parameter conf has been transferred to it. if ($conf = Tools::getValue('conf')) if ($this->json) $this->context->smarty->assign('conf', Tools::jsonEncode($this->_conf[(int)$conf])); else $this->context->smarty->assign('conf', $this->_conf[(int)$conf]); $notifications_type = array('errors', 'warnings', 'informations', 'confirmations'); //valid types of messages foreach($notifications_type as $type) if ($this->json) $this->context->smarty->assign($type, Tools::jsonEncode(array_unique($this->$type))); else $this->context->smarty->assign($type, array_unique($this->$type)); if ($this->json) $this->context->smarty->assign('page', Tools::jsonEncode($page)); else $this->context->smarty->assign('page', $page); / * the function consists only of 2 lines: $this->context->cookie->write(); $this->context->smarty->display($content); //this method of the smarty object converts tpl into html */ $this->smartyOutputContent($this->layout); } |
Most controllers in the admin panel are generated either by using the class Helper or its derivatives. In the classes/helper folder you can find the following classes:
- Helper
- HelperForm
- HelperHelpAccess
- HelperList
- HelperOptions
- HelperView
It is rather easy and convenient to use helpers. For example, you can get the whole list of modules in this way:
1 2 |
$helper = new Helper(); return $helper->renderModulesList($this->modules_list); |
To generate a form you can use this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
$helper = new HelperForm(); $helper->module = $this; $helper->name_controller = 'editorial'; $helper->identifier = $this->identifier; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->languages = $languages; $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name; $helper->default_form_language = (int)Configuration::get('PS_LANG_DEFAULT'); $helper->allow_employee_form_lang = true; $helper->toolbar_scroll = true; $helper->toolbar_btn = $this->initToolbar(); $helper->title = $this->displayName; $helper->submit_action = 'submitUpdateEditorial'; $this->fields_form[0]['form'] = array( 'tinymce' => true, 'legend' => array( 'title' => $this->displayName, 'image' => $this->_path.'logo.gif' ), 'submit' => array( 'name' => 'submitUpdateEditorial', 'title' => $this->l('Save '), 'class' => 'button' ), 'input' => array( array( 'type' => 'text', 'label' => $this->l('Main title'), 'name' => 'body_title', 'lang' => true, 'size' => 64, 'hint' => $this->l('Appears along top of your homepage'), ), array( 'type' => 'text', 'label' => $this->l('Subheading'), 'name' => 'body_subheading', 'lang' => true, 'size' => 64, ), array( 'type' => 'textarea', 'label' => $this->l('Introductory text'), 'name' => 'body_paragraph', 'lang' => true, 'autoload_rte' => true, 'hint' => $this->l('For example... explain your mission, highlight a new product, or describe a recent event.'), 'cols' => 60, 'rows' => 30 ), array( 'type' => 'file', 'label' => $this->l('Homepage logo'), 'name' => 'body_homepage_logo', 'display_image' => true ), array( 'type' => 'text', 'label' => $this->l('Homepage logo link'), 'name' => 'body_home_logo_link', 'size' => 33, ), array( 'type' => 'text', 'label' => $this->l('Homepage logo subheading'), 'name' => 'body_logo_subheading', 'lang' => true, 'size' => 33, ), ) ); $this->_html .= $helper->generateForm($this->fields_form); return $this->_html; |
PrestaShop Modules
Take your online store to the next level with BelVG modules for PrestaShop
Visit the store2. Files location
Admin theme files are located under the following path: your_admin/themes/default/template
In this example default – this is the name of a theme.
If in your module you are using your own tpl files, it is better to place them under this path: modules/your_module/ views/templates /front (admin), this way you will retain compatibility with the paths in the method Helper::createTemplate($tpl_name):
1 2 3 |
$override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->override_folder.$this->base_folder.$tpl_name; or $override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->base_folder.$tpl_name; |
3. Main templates
- your_admin/themes/default/template/layout.tpl – this template can be loaded on all pages as it contains header.tpl, the list of warnings, notification, the body of the page and footer.tpl
- your_admin/themes/default/template/header.tpl
- your_admin/themes/default/template/ footer.tpl
- your_admin/themes/default/template/helpers/form/form.tpl – uses all forms that are generated by the helper class
- your_admin/themes/default/template/ controllers/* – contains templates for admin controllers.
Need an expert PrestaShop development team to take your business to the next level? BelVG can help!