Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

backticks problem

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
TofuWarrior
Smarty Rookie


Joined: 05 Jun 2006
Posts: 18

PostPosted: Tue Aug 26, 2008 3:43 pm    Post subject: backticks problem Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Tue Aug 26, 2008 3:52 pm    Post subject: Reply with quote

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
View user's profile Send private message
TofuWarrior
Smarty Rookie


Joined: 05 Jun 2006
Posts: 18

PostPosted: Wed Aug 27, 2008 11:14 am    Post subject: Awesome Reply with quote

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
View user's profile Send private message
TofuWarrior
Smarty Rookie


Joined: 05 Jun 2006
Posts: 18

PostPosted: Wed Aug 27, 2008 1:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Aug 27, 2008 2:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
TofuWarrior
Smarty Rookie


Joined: 05 Jun 2006
Posts: 18

PostPosted: Wed Aug 27, 2008 3:04 pm    Post subject: Reply with quote

OK. thanks for the pointer.
_________________
We make a living by what we get.
We make a life by what we give.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    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