push smarty variable in {php} array

Hi. So I’m trying to do something genius but I ran into a problem:


  1. I made a php array outside a smarty foreach loop.


  2. I would like to push “smarty variables” inside the “php array”.



    Please pardon me as I’m new to smarty. The following was my attempt.



    {foreach from=$products item=product key=key name=“products”}

    {php}array_push($myArray, “{$product.product_id}” );

    {/php}



    The above failed as I suspected, so my question is: Is there any way to do this?



    Thanks

You’ll get better responses here: [url]Search Results for "forums" | Smarty

Thanks…

Duh! The official smarty site :slight_smile:

Ok, if in Smarty you have var called $blah then in {php} you can access it as:



```php $this->_tpl_vars[‘blah’]; ```



so:



{foreach from=$products item=product key=key name=“products”}

{php}array_push($myArray, “{$product.product_id}” );

{/php}



would be (my untested guess):



{foreach from=$products item=product key=key name=“products”}

{php}array_push($myArray, $this->_tpl_vars[‘product’][‘product_id’] );

{/php}