[Helma-user] New Additions to Template.js

Juerg Lehni juerg at scratchdisk.com
Sun Apr 22 07:29:33 CEST 2007


Hi Maksim,

>>> Also I think it is useful to have functionality to iterate over
>>> objects (hashs) as well as Arrays, since often I want to didpaly a
>>> html table or list of values of an object and I don't worry about
>>> ordering/sorting it.
>>
>> That's good to know, I will add it again then. #length and
>> #isLast will not work on these loops though.
>
> As expected so no probs there.

I started to look into this, and realized it will not be as straight  
forward as I wished. The problem is that for hashes, we have key -  
value pairs, while for arrays we have numeric indices and values. Now  
for a hash, the loop variable probably should contain the value, and  
$variable#index should be the key, instead of the numeric index,  
right? Or should we add #key, and #index would still give a number?

I'm not sure yet how to implement this nicely, as I only know at  
runtime wether a loop object is an array or a hash object. And at  
that time, the loop is already hardcoded, so I cannot switch between  
for-in and normal for loops...

Jürg


More information about the Helma-user mailing list