Page 1 of 1

Joining Smarty variables in the template?

Posted: Sat May 19, 2007 2:32 am
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

Posted: Sat May 19, 2007 11:26 am
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.

Posted: Sat May 19, 2007 11:47 am
by maliskoleather
*sigh* I figured as much... was just hoping someone might know something.

thanks :)