Jump to content

Get all the settings from form to smarty or display function


prestashop_newuser
 Share

Recommended Posts

I am doing a small module in Prestashop. In that module I have taken some variables and want that variables to use in smarty template.

My code for module goes like this

class MyModule extends Module {
public $settings = array();
public function __construct()
{
$this->name = 'mymodule';
$this->tab = 'front_office_features';
$this->version = '1.0.0';
$this->author = 'myname';
$this->need_instance = 0;
$this->bootstrap = 'true';
parent::__construct();
$this->displayName = $this->l('my module');
}

public function install()
{
if(!parent::install() || !$this->registerHook('top') || !$this->registerHook('header')
|| !$this->registerHook('displayHome') || !$this->registerHook('displayMobileTopSiteMap'))

return false;
return true;
}

public function uninstall()
{
if(!parent::uninstall())
return false;
return true;
}

public function getContent() {
$this->_html = '';
$input_var1 = Tools::getValue('input1');
$input_var2 = Tools::getValue('input2');
$input_var3 = Tools::getValue('input3');
array_push($settings,$input_var1, $input_var2, $input_var3)
$this->_html .= $this->renderForm();
return $this->_html;
}

public function displaySettings() {
global $cookie;
var_dump($this->settings);
return $this->display(__FILE__, 'settings.tpl');
}

public function hookHeader() {
return $this->displaySettings();
}

}

Here you can see I have taken a blank array and in that blank array I am pushing all the values for the variables from getContent function. After pushing them I want to fetch them inside displaySettings function. So that I can use all the variable in the samrty template. But its not working. Even I have done var_dump inside displaySettings function its showing me a blank array. So can someone tell me how to get those values in displaySettings settings so that I can use them inside smarty? Any help and suggestions will be really apprecaible. Thanks

Share this post


Link to post
Share on other sites

I think you are missing few things there.

For example check module block social https://github.com/PrestaShop/blocksocial/blob/master/blocksocial.php

and getContent function.

 

First you can use Configuration class to save your settings to database, then renderForm function must have submit and you need to

catch values from that submit in getContent function and save them. Later you can get those values and use in any hook.

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More