Sherif
Sherif

Reputation: 359

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

{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

Answers (7)

Agustin Fiori
Agustin Fiori

Reputation: 41

This works for me:

{php}
$variable= $GLOBALS['smarty']->getTemplateVars('variable');
{/php}

Upvotes: 0

Linga
Linga

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

raju gupta
raju gupta

Reputation: 59

$myValue = $template->getVariable('myVariable')->value;

Upvotes: 0

moldwebs
moldwebs

Reputation: 21

 {php}
 $var = $template->get_template_vars('...')
 {/php}

Upvotes: 2

Scuzzy
Scuzzy

Reputation: 12332

Try using "global"

{php}
global $smarty_object;
$var = $smarty_object->get_template_vars('whatever');
{/php}

Upvotes: -1

Preston
Preston

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

dev-null-dweller
dev-null-dweller

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

Related Questions