View previous topic :: View next topic |
Author |
Message |
johannes Smarty Regular
Joined: 10 May 2003 Posts: 85 Location: Malmö, Sweden
|
Posted: Fri Feb 06, 2004 9:00 am Post subject: concatenate strings in {eval} |
|
|
Hi
I use {eval} func.
I want to use It like this {eval var=$eval_$id}, where the $id is passed from the php. page, (assigned) and then dynamic create the 'var'.
But I cant pass the value $id to the tpl page.... why?
php
$smarty->assign(id, $id);
$smarty->assign($eval, $doc);
$evald = $smarty->fetch('eval.tpl');
eval TPL
I want to use It like this {eval var=$eval_$id}
How do I concatenate the strings and make this work, Is it possible??
{eval var=$eval_'$id'}
{eval var=$eval_"$id"}
and so on... wont work for me!
soon weekend _________________ --------------------------
nice culture on the Internet
www.poeter.se |
|
Back to top |
|
AZTEK Smarty Pro
Joined: 16 Apr 2003 Posts: 235 Location: Purdue University
|
Posted: Fri Feb 06, 2004 9:53 am Post subject: |
|
|
Use {assign} in the template to put the strings in another variable. _________________ "Imagine a school with children that can read and write, but with teachers who cannot, and you have a metaphor of the Information Age in which we live." -Peter Cochrane |
|
Back to top |
|
till Smarty Rookie
Joined: 25 Feb 2004 Posts: 19 Location: Berlin, Germany
|
Posted: Wed Feb 25, 2004 12:05 pm Post subject: |
|
|
Hello,
I have the same problem.
Setup:
I dump variables called "foo_1" and "foo_2" into my template.
How do I access those? The number appended is an ID. So basically, I have another section and loop through an array and need to output "foo_" with the current ID appended.
Any examples?
I am trying with assign and eval, and neither does exactly what I want.
Thanks,
Till |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Feb 25, 2004 12:13 pm Post subject: |
|
|
@till: don't use variable variables, use arrays instead. |
|
Back to top |
|
xscully Smarty n00b
Joined: 25 May 2006 Posts: 2
|
Posted: Thu May 25, 2006 2:32 pm Post subject: |
|
|
sorry to bump this ooooold topic but I having the same 'dilema' as till and I can't change my var_1 var_2 to an array...
how do I access var_1 / var_2 ... using a section or for with fixed loops..
like
[php:1:2d92d02da4]<?
$smarty->assign('var_1', 'Bob');
$smarty->assign('var_2', 'Fred');
$smarty->assign('var_3', 'John');
?>[/php:1:2d92d02da4]
Code: |
{section name=x start=1 loop=3}
{$var_$smarty.section.x.index}
{/section}
|
|
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu May 25, 2006 3:00 pm Post subject: |
|
|
[php:1:de7686e078]<?
$smarty->assign('var', array( '1'=>'Bob', '2'=>'Fred', '3', 'John' ));
?>
[/php:1:de7686e078]
Code: | {section name=x start=1 loop=3}
{$var[$smarty.section.x.index]}
{/section} |
|
|
Back to top |
|
xscully Smarty n00b
Joined: 25 May 2006 Posts: 2
|
Posted: Thu May 25, 2006 3:19 pm Post subject: |
|
|
I can't change the php code... I can't make an array of those variables
I have to find a way to make smarty read those $var_1.....
well... I think I have to write the variables not using {section}
{$var_1}..........
{$var_2}.......... |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu May 25, 2006 3:59 pm Post subject: |
|
|
Well, you can use a clever (ie: ugly hack) arrangement of {capture}{literal}..{/literal}{/capture}{eval} to get a similar result. I won't give the full solution because it is a VERY bad idea to use it. Why not change the data structure? At any-rate, var-vars are not supported so trying to use and/or design for them is going to be a headache. |
|
Back to top |
|
|