Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

How to pass a variable from smarty {$smarty} to php $smart?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
VsOK
Smarty n00b


Joined: 20 Dec 2020
Posts: 2

PostPosted: Fri Dec 25, 2020 6:08 pm    Post subject: How to pass a variable from smarty {$smarty} to php $smart? Reply with quote

Как переменную из Smarty {$smarty}передать в php $smarty

How to pass a variable from smarty {$smarty} to php $smarty
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Fri Dec 25, 2020 6:54 pm    Post subject: Reply with quote

Once Smarty is assigned a value for a variable, the PHP can learn what it is by using getTemplateVars('NAME').
Code:
$Smarty->assign('VAR',"value");
$foobar = $Smarty->getTemplateVars('VAR'); // $foobar equals "value"

However, when Smarty is compiling a template, any values computed at that point is probably not available. This will probably not work (have not tested):
Code:

template.tpl:
{assign $VAR "value"}

PHP:
$output = $Smarty->fetch('template.tpl');
$foobar = $Smarty->getTemplateVars('VAR'); // $foobar is probably empty
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP