hottern
hottern

Reputation: 13

tpl can't see smarty variables

I'm trying to made module for Prestashop. But my tpl file can't see variables.

payicon.php:

function hookFooter($params){
    $group_id="{$base_dir}modules/mymodule/payicon.php";

    $smarty = new Smarty;
    $smarty->assign('group_id', '$group_id');
    return $this->display(__FILE__, 'payicon.tpl');
    return false;
}

payicon.tpl:

<div id="payicon_block_footer" class="block">
    <h4>Welcome!</h4>
    <div class="block_content">
        <ul>
            <li><a href="{$group_id}" title="Click this link">Click me!</a></li>
        </ul>
    </div>
</div>

Update:

This is install:

public function install() {
    if (!parent::install() OR !$this->registerHook('Footer'))
    return false;

    return Db::getInstance()->execute('
        CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'pay_icon` (
            `id_icon` int(10) unsigned NOT NULL,
            `icon_status` varchar(255) NOT NULL,
            `icon_img` varchar(255) DEFAULT NULL,
            `icon_link` varchar(255) NOT NULL,
            PRIMARY KEY (`id_icon`)
        )  ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;');
    return true;
}

Upvotes: 1

Views: 3111

Answers (1)

Ejaz
Ejaz

Reputation: 8872

I don't know about prestashop but I can tell you about smarty and PHP. I can see many obvious issues in the code

1) $base_dir isn't available in the function. add

global $base_dir;

in start of the function to make it available in this function's scope.

2)

 $smarty = new Smarty;

This line shouldn't be there I think. This is initializing a new Smarty instance which has nothing to do with the code outside the function.
Replace this line with

global $smarty;

which will make global $smarty (instance of Smarty class) available in this function

3)

$smarty->assign('group_id', '$group_id');

is wrong. Replace it with

$smarty->assign('group_id', $group_id);  

POSSIBLE Solution
As your question isn't getting much attention, I'll try to come up with an answer to, at least, get you in the right direction (if not solve your issue)

try replacing this function with

public function hookFooter($params){
    global $base_dir;
    global $smarty;

    $group_id="{$base_dir}modules/mymodule/payicon.php";

    $smarty->assign('group_id', '$group_id');
    return $this->display(__FILE__, 'payicon.tpl');
}

Update

My bad :D. forgot to replace the '$group_id' in final code. Try this

public function hookFooter($params){
    global $base_dir;
    global $smarty;

    $group_id="{$base_dir}modules/mymodule/payicon.php";

    $smarty->assign('group_id', $group_id);
    return $this->display(__FILE__, 'payicon.tpl');
}

Upvotes: 1

Related Questions