speed-providing-uncl Posted February 16, 2018 Share Posted February 16, 2018 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 Link to comment Share on other sites More sharing options...
speed-providing-uncl Posted February 16, 2018 Author Share Posted February 16, 2018 My bad, I finally got it working by overriding https://github.com/PrestaShop/PrestaShop/blob/develop/classes/controller/FrontController.php#L489 Link to comment Share on other sites More sharing options...
Jgoss Posted June 4, 2019 Share Posted June 4, 2019 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 2 1 Link to comment Share on other sites More sharing options...
George Bazz Posted August 22, 2019 Share Posted August 22, 2019 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! Link to comment Share on other sites More sharing options...
karimaotmari Posted November 5, 2019 Share Posted November 5, 2019 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 ??!!!! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now