Removed account Posted February 2, 2020 Share Posted February 2, 2020 (edited) Hello, I have a simple PHP file like this: <?php $var="Hello world"; ?> I want to call $var inside the ps_customtext.tpl file, to show it's content. How should I proceed? Thanks for your help. Regards. Edited July 5, 2020 by Removed account . (see edit history) Link to comment Share on other sites More sharing options...
Peeyush Agrawal Posted February 2, 2020 Share Posted February 2, 2020 Hello, You just need to assign this variable on tpl. phpfile.php $var="Hello world"; $smarty->assign("var", $var); Now you can just use {$var} on the tpl file. like - <div>{$var}</div> Link to comment Share on other sites More sharing options...
Removed account Posted February 3, 2020 Author Share Posted February 3, 2020 (edited) Thanks for your answer. So, this is how my code actually look like: my_php_file.php : <?php $var="Hello world"; $smarty->assign("var", $var); ?> ps_customtext.tpl : [...] <p>{$var}</p> [...] But still it doesn't work: the value of $var doesn't appear once I load the page, while all other contents of ps_customtext.tpl do appear. What am I missing? Maybe I have to add some additionnal code into my PHP file to tell it to use Smarty? I don't understand how an annonymous PHP file that is stored somewhere between PS files can generate the $var variable through Smarty if it's not even executed? Edited February 3, 2020 by Studio Creativ (see edit history) Link to comment Share on other sites More sharing options...
Peeyush Agrawal Posted February 3, 2020 Share Posted February 3, 2020 Hello Have you created the object of Smarty class? If not then here $smarty should be an instance of Smarty class. Link to comment Share on other sites More sharing options...
endriu107 Posted February 3, 2020 Share Posted February 3, 2020 Prestashop didn't work like that. If ps_customtext.tpl is a file from module you supposed to add your variable into this module controller, in this controller also you supposed to point hook and file to execute. Link to comment Share on other sites More sharing options...
Removed account Posted February 3, 2020 Author Share Posted February 3, 2020 (edited) 19 hours ago, Peeyush Agrawal said: Hello Have you created the object of Smarty class? If not then here $smarty should be an instance of Smarty class. Hello, no, the file is as you see it above. Can you explain how to do that? I just want to call a variable that comes from an external PHP file, inside a tpl file. Edited February 3, 2020 by Studio Creativ (see edit history) Link to comment Share on other sites More sharing options...
Removed account Posted February 9, 2020 Author Share Posted February 9, 2020 At this point I've included my own function inside CustomText.php file, but then how do call that function inside ps_customtext.php? Link to comment Share on other sites More sharing options...
Murat Kezli Posted March 13, 2021 Share Posted March 13, 2021 On 2/3/2020 at 11:14 PM, endriu107 said: Prestashop didn't work like that. If ps_customtext.tpl is a file from module you supposed to add your variable into this module controller, in this controller also you supposed to point hook and file to execute. This must be a Joke! 😡 Link to comment Share on other sites More sharing options...
endriu107 Posted March 13, 2021 Share Posted March 13, 2021 6 hours ago, Murat Kezli said: This must be a Joke! 😡 No it isn't, this is how programming works. 1 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