Jump to content

Recommended Posts

Hi,

 

I would like to know how I can add a variable in every smarty template. For example, we can use {$urls.base_url} because $urls is an array that has been assigned for all templates.

 

How can I have {$my_global_variable} available everywhere?

 

I tried a hook in hookActionDispatcher with :

public function hookActionDispatcher($params = []){
	$this->context->smarty->assign('my_global_var', [
        'mycontent' => 'abcdef',
      ]);
}

but it's not working, {$my_global_variable} is an undefined index when I dump($this->context->smarty->tpl_vars['my_global_var']) in my controller:initContent. So I think smarty tpl_vars got reassigned somehow between hookActionDispatcher and controller:initContent

 

Thanks

Florian

Share this post


Link to post
Share on other sites

I had the same issue. Just to let others know : there's now a hook for that (since Prestashop 1.7.5.0 apparently). In your module :

public function hookactionFrontControllerSetVariables()
{
	return array(
		'your_variable' => $your_value
	);
}

Then in your template :

${modules.your_module_name.your_variable}

Way better than an override

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
On 6/4/2019 at 3:40 PM, Jgoss said:

I had the same issue. Just to let others know : there's now a hook for that (since Prestashop 1.7.5.0 apparently). In your module :


public function hookactionFrontControllerSetVariables()
{
	return array(
		'your_variable' => $your_value
	);
}

Then in your template :


${modules.your_module_name.your_variable}

Way better than an override

That's extremely helpful, thanks @Jgoss!

 

 

Share this post


Link to post
Share on other sites
On 6/4/2019 at 12:40 PM, Jgoss said:

I had the same issue. Just to let others know : there's now a hook for that (since Prestashop 1.7.5.0 apparently). In your module :


public function hookactionFrontControllerSetVariables()
{
	return array(
		'your_variable' => $your_value
	);
}

Then in your template :


${modules.your_module_name.your_variable}

Way better than an override

how can the call you a prestashop newbie ??!!!!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

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