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

using a variable as part of another variable name to get val

 
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
redbrad0
Smarty Regular


Joined: 03 Feb 2007
Posts: 41

PostPosted: Wed Dec 15, 2021 8:37 pm    Post subject: using a variable as part of another variable name to get val Reply with quote

I have a variable that I can output the contents with {$Price_5056} to get the value but I would like to replace 5056 with another variable like {$Price_{$pricelevel.ID}} but I keep getting errors. Is there something I am doing wrong?

I am using Smarty 3.1.14
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Dec 18, 2021 6:39 am    Post subject: Reply with quote

Use arrays already.
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Sun Dec 19, 2021 5:25 am    Post subject: Reply with quote

Works for me: Smarty 3.1.33.

PHP:
Code:
$pricelevel['ID'] = "5056";
$smarty->assign("Price_5056", "999");
$smarty->assign("pricelevel", $pricelevel);
Smarty:
Code:
{$Price_5056}<br />
{$Price_{$pricelevel.ID}}
Result:
Code:
999
999
What is the error that you get?
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