|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
kiavash2k Smarty n00b
Joined: 11 Oct 2010 Posts: 3
|
Posted: Mon Oct 11, 2010 1:49 pm Post subject: How to load smarty variable inside the {php} {/php} tag |
|
|
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 |
|
kiavash2k Smarty n00b
Joined: 11 Oct 2010 Posts: 3
|
Posted: Tue Oct 12, 2010 7:16 am Post subject: I got it. |
|
|
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. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Oct 12, 2010 2:40 pm Post subject: |
|
|
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 |
|
kiavash2k Smarty n00b
Joined: 11 Oct 2010 Posts: 3
|
Posted: Wed Oct 13, 2010 2:24 pm Post subject: |
|
|
what's the problem of using {php} tags?
I have not any other way to program my ideas. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Oct 13, 2010 2:45 pm Post subject: |
|
|
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 |
|
|
|
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
|