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

calling a variable in a variable confusion

 
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 -> General
View previous topic :: View next topic  
Author Message
guido
Smarty Rookie


Joined: 02 May 2003
Posts: 9

PostPosted: Thu Nov 06, 2003 8:59 pm    Post subject: calling a variable in a variable confusion Reply with quote

I swear I've fixed this before, but right now I"m not sure how Smile

I have a mysql table with fields like:
"buy_amount"
"buy_items"
"hold_amount"
"hold_items"
all in a table called "sessions"

I run a query to get this data into a var $checkout_session
so I call the data into a tpl with:
$tpl->assign("session", $checkout_session);

now the problem comes because I run a section loop to loop through a "buy" section and a "hold" section
ex.
Code:

{section name='i' loop='2'}
{if $smarty.section.i.rownum == 1}
  {assign var='whatpart' value='buy'}
{elseif $fletch.section.i.rownum == 2}
  {assign var='whatpart' value='hold'}
{/if}
--- data ---
{/section}


so in the buy section I'd want to display ideally:

Code:

Amount: {$session.buy_amount} # this would show the actual amount

and in the hold section
Code:

Amount: {$session.hold_amount} # this would show the actual amount


However because I'm running a loop the item infront the _amount needs to be created on the fly...

i've tried:
Code:

$whatpart = "buy";
Amount: {"$session.`$whatpart`_amount"}


but this just returns:
Array.buy__amount instead of the actual value ...

is this even possible?

i've also tried
Code:
 {"`$session`.`$whatpart`_amount"}
without sucess either.
_________________
read docs .. read 'em .. uh oh i'm dumb
Back to top
View user's profile Send private message
guido
Smarty Rookie


Joined: 02 May 2003
Posts: 9

PostPosted: Fri Nov 07, 2003 5:12 pm    Post subject: Reply with quote

as I've done before I've answered my own question Rolling Eyes

on the tpl:
Code:

{ezroll front="session" middle=$whatpart back="_amount"}


in a new plugin:
Code:

function smarty_function_ezroll($params, &$smarty)
{
return $smarty->_tpl_vars[$params["front"]][$params["middle"] . $params["back"]];
}


this returns the correct value....
_________________
read docs .. read 'em .. uh oh i'm dumb
Back to top
View user's profile Send private message
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 -> General 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