FacileCrypto Posted May 13, 2020 Share Posted May 13, 2020 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 More sharing options...
JBW Posted May 18, 2020 Share Posted May 18, 2020 Use assign command https://www.smarty.net/docs/en/language.function.assign.tpl Link to comment Share on other sites More sharing options...
Guest Posted May 18, 2020 Share Posted May 18, 2020 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 More sharing options...
Guest Posted May 18, 2020 Share Posted May 18, 2020 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 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