tags:

views:

318

answers:

2

Hi, I have the following smarty code:

  {foreach from=$additional_fields item=v}
    {if $v.fieldid eq 5}
       {php}
         // several pounds of php code here
         $myfieldid = {$v.fieldid}; // this is wrong
       {/php}
    {/if}
  {/foreach}

I'm trying to grab the current field id with my custom php code, in other words {$v.fieldid}. I've found a few posts referencing $this->_tpl_vars[somevar] to get smarty variables when inside the {php} tags, but that doesn't seem to work with foreach.

I realize that using the {php} tags in smarty is counter-intuitive to the whole smarty concept and like totally lame, but I have my reasons. Thanks for the help!

A: 

If you are using PHP already in a smarty template, why don't you implement foreach as PHP loop and not smarty loop?

m1tk4
There is a bunch of smarty code inside that foreach. I simplified the code for this question. @Bingy - will try your tip and get back to you later today.
Banjer
+1  A: 

change $myfieldid = {$v.fieldid}

to

$myfieldid = $v['fieldid'];

by the way what you are doing is evil!

Bingy
Pure evil! Bingy, that didn't work inside the php tags. In your example, php is looking for an array named $v, but $v is a smarty variable, so it doesn't exist in the php world I suppose. Thanks for the suggestion though.
Banjer