Jump to content

Dynamic global variable in the TPL


FacileCrypto

Recommended Posts

Hi everybody !
I created a dynamic global variable in a php page (module) like this : 
 

define('name'.$idname, $var);

I verified that I return the value in the .tpl with a static variable like this :
 

//FOR PHP PAGE
define('name18', $var);
//TLP PAGE
{$smarty.const.name18}

It's OK for that. 😅

So, now I need to create the dynamic variable in the .tpl ... and that's the problem.

I think I tried all option... especially :

{${$smarty.const.name}{$name.id}}

{$$smarty.const.name{$name.id}

{$smarty.const.name{$name.id}} 
....

I specify that the {$name.id} is OK.

Someone to show me the good way ? NEEEDDDD peace of mind 🙃

Thks for your help my heroes !

Link to comment
Share on other sites

PHP (module):

public function hookActionFrontControllerSetMedia($params)
{
		$myvar = array (
    			'name' => 'here my variable text name',
			'blabla' => 'here my variable text blabla'
		);

		$this->context->smarty->assign(array('customvar' => $myvar));
	
}

TPL:

<span>{$customvar.name}</span>
<span>{$customvar.blabla}</span>

 

Link to comment
Share on other sites

or hookHeader in module:

public function install() 
    {
      
        if (Shop::isFeatureActive())
        {
            Shop::setContext(Shop::CONTEXT_ALL);
        }
        
        if (!parent::install())
        {
            return false;
        }
        
        

        $this->registerHook('header');
        
        return true; 
    }


public function hookHeader($params)
    {
		    global $smarty;
        
        $myvar = array (
    			 'name' => 'here my variable text name',
			     'blabla' => 'here my variable text blabla'
		    );

		    $this->context->smarty->assign(array('customvar' => $myvar));
	
    }

 

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