Jump to content

Display a .tpl through an AdminController


Recommended Posts

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

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

  • 1 year later...

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

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...