Shubb Posted April 10, 2018 Share Posted April 10, 2018 (edited) Hey everyone, I'm currently working on a small module as an internship project, its purpose is to display a custom menu for a catering shop. The module works fine this far, except that the custom menu is submitted through a form in the module's configuration page, and, to be user friendly, I'd like that to be done through a dedicated tab in the back office. Following Fabien Serny's Prestashop module book, I've managed to create the tab, but (and here comes my noobish question) I can't figure out how to use a tpl (say "admin.tpl" or "adminWeekSpecialsController.tpl"). Here's the code so far (it's still pretty basic for that controller) : <?php class AdminWeekSpecialsController extends ModuleAdminController { public function __construct() { $this->table='weekspecials'; $this->className='WeekSpecial'; $this->bootstrap=true; parent::__construct(); } public function initContent() { parent::initContent(); $this->setTemplate('admin.tpl'); } } As soon as the initContent method is uncommented, i get a error 500 and can't access this page. The .tpl is in the %module/Views/Template/Admin folder. Do you have any idea on how to solve this ? Or some documentation other than prestashop's about admincontrollers ? Thanks a lot, Shubb Edit : by the way, I'm working on PS 1.6.1.10 Edited April 10, 2018 by Shubb (see edit history) Link to comment Share on other sites More sharing options...
Shubb Posted April 12, 2018 Author Share Posted April 12, 2018 Hey, I found the solution after some digging into the parent classes. Turns out the .tpl should be located in views/templates/admin/{module_name} To find the name of that last folder, you can do something like $tpl_dir=$this->tpl_folder; var_dump($tpl_dir); die; the result will be the exact name you should give to that folder. Best regards, Shubb Link to comment Share on other sites More sharing options...
Maneesh Posted February 5, 2020 Share Posted February 5, 2020 Hi you can call like this : https://penguin-arts.com/how-to-create-custom-template-for-admin-controller-prestashop/ Link to comment Share on other sites More sharing options...
fbenoist.com Posted February 5, 2020 Share Posted February 5, 2020 You can use the helper view. Example for the controller /modules/module_name/controller/admin/AdminSampleViewController.php class AdminSampleViewController extends ModuleAdminController { public function __construct() { $this->display = 'view'; $this->bootstrap = true; parent::__construct(); } } The template used will be /modules/module_name/views/templates/admin/sample_view/helpers/view/view.tpl {extends file="helpers/view/view.tpl"} {block name="override_tpl"} <p> Hello World ! </p> {/block} How to find the view.tpl path ? If the controller name is AdminSampleViewController. First: Remove Admin and Controller from name Second: change name from CamelCase to underscore_case The full path becomes : views/templates/admin/sample_view/helpers/view/view.tpl 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