BorisTrn Posted March 31, 2021 Share Posted March 31, 2021 Hi there, I have a publicKey set in a form in back office that I need to be inserted into a front.js file Do you have a clue to how I could do it ? 1. I tried to add this to my main php module file: $this->context->smarty->assign('publicKey', Configuration::get('12345678')); 2. I tried to add this to the front.js (wich is called by $this->context->controller->addJS($this->_path.'/views/js/front.js'); in the main php file) var recaptchapublickey = "{$recaptchaPublicKey}"; Do I need to make a tpl with js and {literal} to add my javascript code or is there a way to pass a var from backend php to frontend js with smarty? Thanks Link to comment Share on other sites More sharing options...
elburgl69 Posted March 31, 2021 Share Posted March 31, 2021 Only *.tpl files are processed by smarty, .js files not. In your module, as you already had: $this->context->smarty->assign('publicKey', Configuration::get('12345678')); In the a template file your module processes add the following: <script> var recaptchapublickey = "{$publicKey}"; </script> The correct value should be available in your front.js. Link to comment Share on other sites More sharing options...
BorisTrn Posted March 31, 2021 Author Share Posted March 31, 2021 6 minutes ago, elburgl69 said: Only *.tpl files are processed by smarty, .js files not. In your module, as you already had: $this->context->smarty->assign('publicKey', Configuration::get('12345678')); In the a template file your module processes add the following: <script> var recaptchapublickey = "{$publicKey}"; </script> The correct value should be available in your front.js. Thanks you for your time elburgl69 I will then add a TPL to handle that Have a nice day 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