Hi all!
I need to access a certain element of an array . No probs using a fixed value:
{assign var=eventlist value=$xml->veranstaltung}
{$eventlist[1]->datum}
--> works
but when I use a variable:
{assign var=eventlist value=$xml->veranstaltung}
{$eventlist[$event]->datum}
--> does not work. The value of $event is 1 ...
I searched for a long time, but none of the given solutions work.
In most cases people advise to use
{$eventlist.$event.datum}
but this does not work. So doesn't
{$eventlist.$event->datum}
But there must be a solution, or is this impossible? How do I do this?
Cheers,
Alex
Smarty: Access to array element using a variable?
Re: Smarty: Access to array element using a variable?
This should work:
vilkis
Code: Select all
{assign var=eventlist value=$xml->veranstaltung}
{assign var=element value=$eventlist.$event}
{$element->datum}
Re: Smarty: Access to array element using a variable?
I have no similar smarty object now, so can't test it.
What about:
vilkis
What about:
Code: Select all
{assign var=eventlist value=$xml->veranstaltung}
{assign var=element value=$eventlist[$event]}
{$element->datum}
Re: Smarty: Access to array element using a variable?
Both codes should work. Check if the value of $event is 1.
vilkis
vilkis
Re: Smarty: Access to array element using a variable?
here's the code:
and this is the output:
$event : 1
$element->datum :
$eventlist[1]->datum : 15.06.2012
$eventlist[$event]->datum :
$eventlist.$event->datum :
$xml->veranstaltung[1]->datum : 15.06.2012
$xml->veranstaltung.$event->datum :
It only works with fixed values.
Cheers,
ALex
Code: Select all
{assign var=eventlist value=$xml->veranstaltung}
{assign var=element value=$eventlist[$event]}
<p>$event : {$event}
<p>$element->datum : {$element->datum}
<p>$eventlist[1]->datum : {$eventlist[1]->datum}
<p>$eventlist[$event]->datum : {$eventlist[$event]->datum}
<p>$eventlist.$event->datum : {$eventlist.$event->datum}
<p>$xml->veranstaltung[1]->datum : {$xml->veranstaltung[1]->datum}
<p>$xml->veranstaltung.$event->datum : {$xml->veranstaltung.$event->datum}
$event : 1
$element->datum :
$eventlist[1]->datum : 15.06.2012
$eventlist[$event]->datum :
$eventlist.$event->datum :
$xml->veranstaltung[1]->datum : 15.06.2012
$xml->veranstaltung.$event->datum :
It only works with fixed values.
Cheers,
ALex
Re: Smarty: Access to array element using a variable?
if outputs 1, then I have no idea why my suggestions do not work for you.
vilkis
Code: Select all
{$event|count_characters:true}
vilkis
Re: Smarty: Access to array element using a variable?
<p>$event : {$event} - {$event|count_characters:true}vilkis wrote:ifoutputs 1, then I have no idea why my suggestions do not work for you.Code: Select all
{$event|count_characters:true}
vilkis
gives
$event : 1 - 1
Seems that I am out of luck.
Cheers,
Alex
Re: Smarty: Access to array element using a variable?
What you have when {$eventlist|@print_r}?
Marek A.
Marek A.