Reputation: 359
Very simple question, is it possible to use a smarty var inside the {php}{/php} tags. I know it's deprecated, pointless, not recommended, etc., but please, I am looking for a simple patch !
Something like
{php}
$result = mysql_query("SELECT value FROM table WHERE fieldid = 9 AND relid = {MYSMARTYVAR}");
{/php}
Thank you!
Update: I`ve tried the following methods.
1-$var = $this->get_template_vars('smarty_var');
2-$var = $smarty->getTemplateVars('smarty_var');
3-$var = $this->_tpl_vars['smarty_var'];
All give me Fatal errors, $this when not in object context etc. I`m in the WHMCS environment, if this explains why perhaps certain things are blocked or disabled?
Update 2; found a solution more simple than it seemed, I feel silly: $var= "{$mysmartyvar}";
Thanks everyone!
Upvotes: 5
Views: 12152
Reputation: 41
This works for me:
{php}
$variable= $GLOBALS['smarty']->getTemplateVars('variable');
{/php}
Upvotes: 0
Reputation: 10573
Answer from the OP. It may be helpful to others.
It is very simple.
$var= "{$mysmartyvar}";
This is working for me.
Upvotes: 0
Reputation: 12332
Try using "global"
{php}
global $smarty_object;
$var = $smarty_object->get_template_vars('whatever');
{/php}
Upvotes: -1
Reputation: 1059
Use $this->get_template_vars('smarty_var')
to get a Smarty variable.
$result = mysql_query("SELECT value FROM table WHERE fieldid = '9' AND relid = '" . $this->get_template_vars('smarty_var') . "'");
Upvotes: 7
Reputation: 29492
Yes, all variables are stored in $this->_tpl_vars
, so it should look like this:
{php}
$result = mysql_query("SELECT value FROM table WHERE fieldid = 9 AND relid = {$this->_tpl_vars['MYSMARTYVAR']}");
{/php}
Upvotes: 0