Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Assign in PHP

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
TiXav
Smarty n00b


Joined: 08 Feb 2012
Posts: 1

PostPosted: Wed Feb 08, 2012 2:01 pm    Post subject: Assign in PHP Reply with quote

Hello,

In the file "product-list.tpl",

in the loop "{foreach from=$products item=product name=products}",

I want to get in tags "{php} {/php}" the variable "$product->id" that I will use in a php function that I created.

Do you have a solution?

Thanks
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Feb 09, 2012 4:28 pm    Post subject: Reply with quote

Write a plugin, and use that in the template.

Code:
{foreach from=$products item=product name=products}
    {myfunction id=$product->id}
{/foreach}


Otherwise you can use in {php} tags (turn on backward compatability):

Code:
$product = $smarty->getTemplateVar("product");
 echo $product->id;


in PHP 2.x it is $smarty->get_template_var()
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP