Forums / Developer / a variable witch is defind as integer becomes an array
Fox Mulder
Tuesday 18 September 2007 5:57:44 am
Hello In the code down i can't understand how it is possible variable $last=0 witch has a value 0 to become an array with value few rows down {set lastlevel=$last.level} . In {set lastlevel=$last.level} variable last is already array and has value. How it happens?
Please help
$last=0{*?template charset="utf-8"?*}
{def $depth=1 $last=0 $lastlevel=0 $x=1} {def $mainMenu=treemenu( $module_result.path, $module_result.node_id, , 0, 4)} <ol>{foreach $mainMenu as $menu}
{set lastlevel=$last.level} {if and($lastlevel|ne(0), $lastlevel|gt($menu.level))} </ol> </li> {set lastlevel=$lastlevel|sub(1)} {/if} <li> {if and($last | ne(0), $last.level|lt($menu.level))} <ol> <li{$menu.is_selected|choose('',' class="selected"')}> {/if} <a {$menu.is_selected|choose('','class="selected"')} href={$menu.url_alias|ezurl}>{$menu.text|shorten(25)}</a> </li> {set last=$menu} {/foreach} {while $depth |gt(1)} </li> </ol> {set depth=$depth|sub(1)} {/while} </ol>
Laurent BOURREL
Tuesday 18 September 2007 6:53:38 am
Where did you find this code ?
Tuesday 18 September 2007 6:55:42 am
int the comment in this page http://ez.no/doc/ez_publish/technical_manual/3_8/reference/template_operators/miscellaneous/treemenu
Tuesday 18 September 2007 8:43:34 am
OK, i didn't see one of the last line :{set last=$menu}
At the first iteration, last is an integer, and for the next iterations, it becomes an array . That's why there's a test on the value and the level attribute.
Tuesday 18 September 2007 11:54:46 pm
Hmmm ... I think that in first interation $lastlevel is empty and $last is zero so i don't understand how can be done $lastlevel|ne(0) when there is no value for $lastlevel.i think it is some bug ...
Wednesday 19 September 2007 12:21:41 am
and one more thing ... after first ineration $last becomes an array, so how it is possible to compare $last | ne(0) (if an array not equal to zero). So if there is someone who already have those answers, please tell us.