Jump to content

Call PHP variable in a .tpl


Recommended Posts

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 by Studio Creativ (see edit history)
Link to comment
Share on other sites

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 by Studio Creativ (see edit history)
Link to comment
Share on other sites

  • 8 months later...
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...