Joining Smarty variables in the template?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
maliskoleather
Forum Contributor
Posts: 155
Joined: Tue May 15, 2007 2:19 am
Contact:

Joining Smarty variables in the template?

Post by maliskoleather »

Im using Smarty as a templating system for a project im currently working on.

In my php file, im assigning an integer to a variable, and passing that to a template. Then, in the template i want to add a prefix onto that number. Im then trying to use that to call a constant from the configuration file.

for example:

Code: Select all

{$smarty.config."id_`$data.result`"}
but it seems the only way i can get this to work is by assigning a variable in the template, then using that var to call the constant.

Code: Select all

{assign var="idnum" value="id_`$data.result`"}
{$smarty.config.$idnum}
and yes, this works fine... i just dont like having to assign so many unnessicary variables just to call a value.
also, the only reason im not combining these on the script level is because the script is executed for several templates, and each template needs a different prefix, as they are calling different variables for the same id.

Its a simple concept, but i cant figure it out for the life of me. I've been scanning the documentation for a while now, and don't see anything that referrs to what Im looking for.

If anyone knows how to do this, I would greatly appreciate the help
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

Your second method is the only way that will work. Variables and elements cannot be parsed the way you are wanting to do in your first example. You have to remember that even though some things are similar to PHP it is still just a templating language and there will always be some limitations to what you can do.
User avatar
maliskoleather
Forum Contributor
Posts: 155
Joined: Tue May 15, 2007 2:19 am
Contact:

Post by maliskoleather »

*sigh* I figured as much... was just hoping someone might know something.

thanks :)
Post Reply