|
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 |
TofuWarrior Smarty Rookie
Joined: 05 Jun 2006 Posts: 18
|
Posted: Tue Aug 26, 2008 3:43 pm Post subject: backticks problem |
|
|
Hi
Everyone,
I hope some smarty head can help me. I'm sure this is very simple and I am being dumb. I would be really grateful.
I am trying to reference dynamically named fields in request like this.
{$smarty.request.db_`$suffix`firstName}
I have the same form elements being dynamically created multiple times by a loop so am naming the fields
db_1firstName
db_2firstName etc for each iteration of the form.
How can I reference the appropriate values using the variable $suffix.
What I have tried above throws an error and nopthing else I try works.
Thanks,
Paul _________________ We make a living by what we get.
We make a life by what we give. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Aug 26, 2008 3:52 pm Post subject: |
|
|
You can't make parts of the index dynamic directly.
Here is the workaround
Code: |
{assign var=foo value="db_`$suffix`firstName"}
{$smarty.request.$foo}
|
|
|
Back to top |
|
TofuWarrior Smarty Rookie
Joined: 05 Jun 2006 Posts: 18
|
Posted: Wed Aug 27, 2008 11:14 am Post subject: Awesome |
|
|
Thanks for replying. that's just what I need. _________________ We make a living by what we get.
We make a life by what we give. |
|
Back to top |
|
TofuWarrior Smarty Rookie
Joined: 05 Jun 2006 Posts: 18
|
Posted: Wed Aug 27, 2008 1:03 pm Post subject: |
|
|
Is it possible to do something like this to refer dynamically to objects individual_1 individual_2 etc
{assign var="object" value="individual_`$suffix`"}
{$object->getName()} _________________ We make a living by what we get.
We make a life by what we give. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Aug 27, 2008 2:43 pm Post subject: |
|
|
No thats not possible.
This first case does work because it was just the index of an array which had to be dynamic. Not the name of the variable. |
|
Back to top |
|
TofuWarrior Smarty Rookie
Joined: 05 Jun 2006 Posts: 18
|
Posted: Wed Aug 27, 2008 3:04 pm Post subject: |
|
|
OK. thanks for the pointer. _________________ We make a living by what we get.
We make a life by what we give. |
|
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
|