dianacd Posted July 14, 2020 Share Posted July 14, 2020 Hello!! I want to create some custom global constants that I can access from all TPL, this is some information like specific emails or external URLs that I want to put across the webpage, and in case that they change I just need to update the global constant and not all the TPLs that contain the information. Is there a way to create a custom global constant? Link to comment Share on other sites More sharing options...
Razi Posted July 14, 2020 Share Posted July 14, 2020 hello, its possible using two different methods 1st is by override the front controller "classes/controller/FrontController.php" and assign your new variable in function assignGeneralPurposeVariables by using templateVars array. second is using hook, for this you need to make small module and use hook actionFrontControllerSetVariables Example: public function hookactionFrontControllerSetVariables() { $new_variable = 'hello world'; return array( 'new_variable' => $new_variable ); } And you can use this in template like this: ${modules.module_name.new_variable} Link to comment Share on other sites More sharing options...
Guest Posted July 14, 2020 Share Posted July 14, 2020 3 hours ago, Razi said: hello, its possible using two different methods 1st is by override the front controller "classes/controller/FrontController.php" and assign your new variable in function assignGeneralPurposeVariables by using templateVars array. second is using hook, for this you need to make small module and use hook actionFrontControllerSetVariables Example: public function hookactionFrontControllerSetVariables() { $new_variable = 'hello world'; return array( 'new_variable' => $new_variable ); } And you can use this in template like this: ${modules.module_name.new_variable} In tpl: {$new_variable} Link to comment Share on other sites More sharing options...
dianacd Posted July 14, 2020 Author Share Posted July 14, 2020 Thanks a mill! I will try it and post the outcome! Link to comment Share on other sites More sharing options...
dianacd Posted July 14, 2020 Author Share Posted July 14, 2020 8 hours ago, Razi said: hello, its possible using two different methods 1st is by override the front controller "classes/controller/FrontController.php" and assign your new variable in function assignGeneralPurposeVariables by using templateVars array. second is using hook, for this you need to make small module and use hook actionFrontControllerSetVariables Example: public function hookactionFrontControllerSetVariables() { $new_variable = 'hello world'; return array( 'new_variable' => $new_variable ); } And you can use this in template like this: ${modules.module_name.new_variable} Thanks for your advice! I did it in the fast way, I override the FrontController and it works as expected Link to comment Share on other sites More sharing options...
dianacd Posted July 14, 2020 Author Share Posted July 14, 2020 I was wondering, is there a way to use this variables from tpl created in Ap ShortCode? I tried but they are not recognized! Link to comment Share on other sites More sharing options...
Guest Posted July 14, 2020 Share Posted July 14, 2020 (edited) https://devdocs.prestashop.com/1.7/contribute/documentation/shortcodes/ https://addons.prestashop.com/en/seo-natural-search-engine-optimization/47611-shortcode-builder.html#overview https://mypresta.eu/modules/front-office-features/shortcodes.html Edited July 14, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
dianacd Posted November 1, 2020 Author Share Posted November 1, 2020 (edited) Finally I created a module to set my global variables. They are accesible only from TPL files though. Here is the code in case that it may be useful for anyone: https://github.com/dianacd/prestashop_modules/tree/master/mcr_global_var Edited November 1, 2020 by dianacd (see edit history) 1 Link to comment Share on other sites More sharing options...
zion Posted November 2, 2020 Share Posted November 2, 2020 (edited) On 11/1/2020 at 6:36 PM, dianacd said: Finally I created a module to set my global variables. They are accesible only from TPL files though. Here is the code in case that it may be useful for anyone: https://github.com/dianacd/prestashop_modules/tree/master/mcr_global_var You can access from .tpl with {$your_variable1} ? I am trying to send variables from a module to the invoice template. I can't get it to work, I'm doing something wrong: S I have also tried to load these variables into $data array of "HTMLTemplateInvoice.php", trying to save from the module as smarty variable, but I also can't edit: By doing tests, with the override I can show the variable in the theme's .tpl, but not in the invoice tpl. With the module method I can't, I have tested the functions; "hookDisplayPDFInvoice ()" and "hookactionFrontControllerSetVariables ()" what am I missing? Edited November 3, 2020 by anderrios (see edit history) Link to comment Share on other sites More sharing options...
dianacd Posted November 3, 2020 Author Share Posted November 3, 2020 19 hours ago, anderrios said: You can access from .tpl with {$your_variable1} ? I am trying to send variables from a module to the invoice template. I can't get it to work, I'm doing something wrong: S I have also tried to load these variables into $data array of "HTMLTemplateInvoice.php", trying to save from the module as smarty variable, but I also can't edit: By doing tests, with the override I can show the variable in the theme's .tpl, but not in the invoice tpl. With the module method I can't, I have tested the functions; "hookDisplayPDFInvoice ()" and "hookactionFrontControllerSetVariables ()" what am I missing? You can access from .tpl using {$modules.mcr_global_var.your_variable} To use my code you can download the only the mcr_global_var.php file and compress it into a folder and install it as a module from the BO, or just add it manually to your modules folder, then you can update the files from the modules folder with your variables anytime. Link to comment Share on other sites More sharing options...
zion Posted November 3, 2020 Share Posted November 3, 2020 39 minutes ago, dianacd said: You can access from .tpl using {$modules.mcr_global_var.your_variable} To use my code you can download the only the mcr_global_var.php file and compress it into a folder and install it as a module from the BO, or just add it manually to your modules folder, then you can update the files from the modules folder with your variables anytime. Thank you very much for your quick reply, I managed to get it to work with your module in the theme's .tpl, but I still can't get it to work in "invoice.addresses-tab.tpl". Maybe I have to first bring the information to "HTMLTemplateInvoice.php" and load it into the $ data array? 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