Home is for the experience. Projects are for the ones who are interested!

How To Assign Custom Template to Controller Prestashop Back Office

How To Assign Custom Template to Controller Prestashop Back Office

In this tutorial I will show you how to assign custom template a an admin controller in prestashop. This code can be used if you already have a controller created because I will put a little below the functions which will add the tab in left admin panel of prestashop. This feature is a little difficult because there are not so many tutorials especially if you are a begginer with prestashop. To achive this functionality we have to go through some steps.

First go to the main module file and add the following piece of code:

public function installTab(){
        $tab = new Tab();
        $tab->active = 1;
        $tab->class_name = static::CLASS_NAME;
        $tab->name = array();
        foreach (Language::getLanguages(true) as $lang) {
            $tab->name[$lang['id_lang']] = "My Module";
        }
    $tab->id_parent = (int) Tab::getIdFromClassName('AdminCatalog');
        $tab->module = $this->name;
        return $tab->add();
    }

The above function will create a new link admin under the Catalog dropdown in left admin menu. You can change the position for the menu by changing the 'AdminPanel' parameter, you can find all types on google. That function get the id of the dropdown and save it in the database. You can change the id from phpmyadmin in _ps_tab table too. Next, you have to call the above function in install() function and prestashop will make the hard work for you. Now, only thing you need to do is to assign the custom template file in controller and that's it. In the next tutorials I will show how to add sub page to a custom template admin controller. We will add a new parameter to the url and we will create a sub page like CMS edit pages. If you want to see the full tutorial for how to create custom admin controller with custom template check the post. Let me know if you have any questions in the comments section and I will try to help you.

Leave a Reply

Your email address will not be published. Required fields are marked *