开发者

smarty code - access variables inside {php} tag

I know we should avoid the {php} tag inside any template engine, still, let's assume that it's the only way on this case.

Considering this, I would like to request some help in order to grab smarty string for php consumption.

On this case, I would like to access $result.domain inside the srtstr php function.

What am I doing wrong?

{foreach key=period item=regoption from=$result.regoptions}
{if $regoption.$domain}
{if $domain eq "transfer"}
{php}
   $domainName = $result.domain;
   $tld = strstr($domainName, '.');
{/php}

{if $tld eq '.gt'}
   <p>Something</p>
{else}
<option value="{$period}">{$period} {$LANG.orderyears} @ {$regoption.$domain}</option>
{/if}
{/if}
{/if}
{/foreach}

Than开发者_StackOverflow社区ks in advance,

MEM


You can use get_template_vars, just make sure you use $this instead of $smarty

$this->get_template_vars('foo')

It would be a much better idea to rewrite what you are doing as a smarty plugin though

EDIT:

In your example you could do something like

$result = $this->get_template_vars('result');
$domainName = $result.domain;


$this doesn't work for us, we finally got it using $GLOBALS variable like this:

$variable= $GLOBALS['smarty']->getTemplateVars('variable');


Don't {PHP} tags reference PHP Variables, not variables set through $smarty->assign ?

Perhaps you are trying to access something inside a {PHP} that you set through $smarty->assign ?

Try accessing the object as it is named in your .php file that calls $smarty->dispay().


In later versions of smarty you have to use $template, instead of $this.

For example:

$template->get_template_vars('foo')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜