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

How to load smarty variable inside the {php} {/php} tag

 
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
kiavash2k
Smarty n00b


Joined: 11 Oct 2010
Posts: 3

PostPosted: Mon Oct 11, 2010 1:49 pm    Post subject: How to load smarty variable inside the {php} {/php} tag Reply with quote

I have write a code inside smarty and now i need to call php inside my tpl file.

I do the following:

I have a variable in smarty like this:

Code:
{$product.id_product}


and now it respond product id to me in smarty. everything is ok until now.

i call php here:

Code:

{php}
// I need to have the product.id_product variable here but it doesnt work.

$prod_id = $this->_tpl_var[product.id_product];

echo $prod_id;

{/php}


but it doesnt work right now can some one help me to fix this?

Thanks
Back to top
View user's profile Send private message
kiavash2k
Smarty n00b


Joined: 11 Oct 2010
Posts: 3

PostPosted: Tue Oct 12, 2010 7:16 am    Post subject: I got it. Reply with quote

just i need to change my code to to this:

in smarty i need to assign my array to a new var like this:
Code:
{assign var='prod' value=$product.id_product}


then in {php} ... {/php} just i need to change the code to this:

Code:

{php}
    $prod_id = $this->get_template_vars('prod');
    echo $prod_id;
{/php}


Now it's work great. Wink
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Oct 12, 2010 2:40 pm    Post subject: Reply with quote

You don't need {assign} for a temporary variable.

Code:
{php}
    $var = $this->get_template_vars('product');
    echo $var['id_product'];
{/php}


Anyway you should avoid using {php} tags. It's bad practise. Any good reasion that you need it?
Back to top
View user's profile Send private message
kiavash2k
Smarty n00b


Joined: 11 Oct 2010
Posts: 3

PostPosted: Wed Oct 13, 2010 2:24 pm    Post subject: Reply with quote

what's the problem of using {php} tags?

I have not any other way to program my ideas.
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Wed Oct 13, 2010 2:45 pm    Post subject: Reply with quote

kiavash2k wrote:
what's the problem of using {php} tags?

I have not any other way to program my ideas.


Instead of embedding PHP in templates, write a plugin and call the plugin from within the template. Don't use {php} tags, they just cause more problems than they solve. You don't want this mess in the template, keep the template focused on presentation.
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