ThibaultWUN Posted October 12, 2020 Share Posted October 12, 2020 (edited) I have a php file in which I assign a var $this->context->smarty->assign('test', 'test' ); Immediately after, I display my template. return $this->display(__FILE__, 'template.tpl'); In my template, I try to access my var <div style="display:none;">{$test|var_dump}</div> <div style="display:none;">{$test}</div> The first line gives me NULL. How is it possible ? What am I doing wrong ? Edited October 13, 2020 by ThibaultWUN solved (see edit history) Link to comment Share on other sites More sharing options...
Guest Posted October 13, 2020 Share Posted October 13, 2020 (edited) {$test|@var_dump} {$test|@print_r} Edited October 13, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
ThibaultWUN Posted October 13, 2020 Author Share Posted October 13, 2020 (edited) I does not work. {$test|@var_dump} => NULL {$test|@print_r} => 1 I need to be able to use this variable in my template. {$cookie|var_dump} => WORKS FINE ! Edited October 13, 2020 by ThibaultWUN (see edit history) Link to comment Share on other sites More sharing options...
Guest Posted October 13, 2020 Share Posted October 13, 2020 (edited) sample 1: $this->context->smarty->assign(array( 'test' => 'test', 'test2' => 'test2', )); tpl: {$test}<br />{$test2} ================================================== sample 2: $test_array = array('test 1', 'test 2'); $this->context->smarty->assign(array( 'test' => $test_array, )); tpl: {foreach from=$test item=item} {$item}<br/> {/foreach} Edited October 13, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
coeos.pro Posted October 13, 2020 Share Posted October 13, 2020 have you test {debug} in the file tpl ? Link to comment Share on other sites More sharing options...
ThibaultWUN Posted October 13, 2020 Author Share Posted October 13, 2020 Quote sample 1: $this->context->smarty->assign(array( 'test' => 'test', 'test2' => 'test2', )); tpl: {$test}<br />{$test2} ================================================== sample 2: $test_array = array('test 1', 'test 2'); $this->context->smarty->assign(array( 'test' => $test_array, )); tpl: {foreach from=$test item=item} {$item}<br/> {/foreach} It did not work either... I was unable to display me page at all Link to comment Share on other sites More sharing options...
ThibaultWUN Posted October 13, 2020 Author Share Posted October 13, 2020 Quote have you test {debug} in the file tpl ? Unfortunately, the website was created without a long term vision and there is no test version, only the production version. I read that it is quite risky to use {debug} in a live site as it can really slow things down. I am actually forced to create hidden div to see if I can get the data I need. A nightmare... Even more so as I am enable to get it ! Link to comment Share on other sites More sharing options...
Rachit Agarwal Posted October 13, 2020 Share Posted October 13, 2020 19 hours ago, ThibaultWUN said: I have a php file in which I assign a var $this->context->smarty->assign('test', 'test' ); Immediately after, I display my template. return $this->display(__FILE__, 'template.tpl'); In my template, I try to access my var <div style="display:none;">{$test|var_dump}</div> <div style="display:none;">{$test}</div> The first line gives me NULL. How is it possible ? What am I doing wrong ? Please try with below command for assigning var in php file: Context::getContext()->smarty->assign('test','test'); Try with this and let me know if you get success. 1 Link to comment Share on other sites More sharing options...
ThibaultWUN Posted October 13, 2020 Author Share Posted October 13, 2020 Quote Please try with below command for assigning var in php file: Context::getContext()->smarty->assign('test','test'); Try with this and let me know if you get success. It does not work... Perhaps I should have said it earlier but I am in a module inside a hook function... My main goal here is actually to be able to show info about users groups. I need to know i which group my user is and to retrieve id's of users belonging to a group. If this changes the problem... Link to comment Share on other sites More sharing options...
Guest Posted October 13, 2020 Share Posted October 13, 2020 The problem will be elsewhere. Everything is working. Without your codes, we can only guess where you have a mistake. in module: in tpl: (sample) on category page: Link to comment Share on other sites More sharing options...
ThibaultWUN Posted October 13, 2020 Author Share Posted October 13, 2020 Quote The problem will be elsewhere. Everything is working. You answer got me thinking... I made a stupid mistake and my code was is the wrong hook. I saw you screenshot showing the hookHeader and I realised it... I works fine now. Thank you all for your replies ! Link to comment Share on other sites More sharing options...
Guest Posted October 13, 2020 Share Posted October 13, 2020 I gladly helped. 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