Craig van Tonder
Craig van Tonder

Reputation: 7687

Prestashop 1.6 - Back Office - Smarty - Creating a module that makes a simple blank page?

I am trying to add some functionality to my shop and have spent the past two days trying to come to grasp with how smarty actually works within prestashop or rather in general.

I have so far made a module that can install, on install it creates a tab on the left menu, I can click on the tab and it will load the controller but this is where i get stuck... I can't figure out how to display custom content within that state.

What i would like is very simple, just a paragraph of text and a button. When clicking the button i will do a few things and record a few things then show the results as a simple report.

So for starters... I'd like to create the page with the paragraph and button.

So i have created a folder in the module diretory called priceupdate

Inside of this there is:

/priceupdate.php

<?php
if (!defined('_PS_VERSION_'))
    exit;

class PriceUpdate extends Module
{
    public function __construct()
    {
        $this->name = 'priceupdate';
        $this->tab = 'quick_bulk_update';
        $this->version = '0.8';
        $this->author = 'Me';
        $this->need_instance = 0;
        $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->l('Pricing Update');
        $this->description = $this->l('Adds functionality relating to maintaining product my prices.');  

        $this->confirmUninstall = $this->l('Are you sure you would like to uninstall?');

    }

    public function install()
    {
        if (!parent::install()
            || !$this->installModuleTab('AdminPricingUpdate', array(1=>'Pricing Update'), 0))
            return false;
        return true;
    }

    public function uninstall()
    {
        if (!parent::uninstall()
            || !$this->uninstallModuleTab('AdminPricingUpdate', array(1=>'Pricing  Update'), 0))
            return false;
        return true;
    }

    private function installModuleTab($tabClass, $tabName, $idTabParent)

    {    
        $tab = new Tab();

        $tab->name = $tabName;

        $tab->class_name = $tabClass;

        $tab->module = $this->name;

        $tab->id_parent = $idTabParent;

        if(!$tab->save())

            return false;

        return true;

    }

    private function uninstallModuleTab($tabClass)

    {       
        $idTab = Tab::getIdFromClassName($tabClass);

        if($idTab != 0)

        {

            $tab = new Tab($idTab);

            $tab->delete();

            return true;

        }

        return false;

    }

}
?>

And

/controllers/admin/AdminPricingUpdateController.php

<?php
class AdminPricingUpdateController extends AdminController
{

    public function __construct()

    {

        $this->lang = (!isset($this->context->cookie) || !is_object($this->context->cookie)) ? intval(Configuration::get('PS_LANG_DEFAULT')) : intval($this->context->cookie->id_lang);

        parent::__construct();

    }

    public function display(){

        parent::display();

    }

    public function renderList() {

        return $this->context->smarty->fetch(dirname(__FILE__).'/content.tpl');

    }   
}
?>

This works however where I am stuck relates to the content.tpl part. What goes inside of this the content.tpl file in order to get it to make a blank page of content within the content area of the admin section?

I've looked through the manual and spent countless hours on forums looking though questions, tried to figure it out by breaking down other modules but i've found it too complex to really understand what is what.

If anyone could help me to understand this or point me to a source of info on this specific subject then it would be greatly appreciated, thanks!

Upvotes: 2

Views: 8264

Answers (1)

PrestaShopDeveloper
PrestaShopDeveloper

Reputation: 3118

Check that answer

If you need "a blank page of content within the content area of the admin section" you need to make the content.tpl blank.

Note in my example that you do not have to set the name of the template if it's called "content.tpl".

Upvotes: 2

Related Questions