Sherif Sherif - 1 year ago 168
PHP Question

Using smarty variable within {php} tags

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


$result = mysql_query("SELECT value FROM table WHERE fieldid = 9 AND relid = {MYSMARTYVAR}");


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!

Answer Source

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') . "'");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download