in reply to Re: HTML::Template::Compiled - TMPL_EACH
in thread HTML::Template::Compiled - TMPL_EACH

ability to "sort by keys" when we use TMPL_EACH.
I've thought about that. I was actually thinking about to sort by default, so I would change it internally to a loop over keys(). One wouldn't use the unsorted output anyway in production, I guess. What about an attribute CMP which can have the values num or alpha?

edit: I just coded it, it's an easy change. <%each hash sort=num %>...
Now one would probably like to have the possibility to reverse the sort order and to sort by values. I'm open to any suggestions on this.

Replies are listed 'Best First'.
Re^3: HTML::Template::Compiled - TMPL_EACH
by mmanso (Initiate) on Sep 05, 2008 at 23:53 UTC
    Hi there,

    You could have something like:

    <%each hash sort=num reverse=1 %>

    Meaning that by default it wouldn't reverse.

    The solution of having sort=num or alpha looks good to me.

      or how about
      <%each hash sort=-num %>
      less typing =)

      edit: on the other hand, an attribute 'reverse' could also be used for tmpl_loop

        In my oppinion when you use TMPL_LOOP you already took care of sorting when you build the array to feed the TMPL_LOOP.

        Any of both solutions looks fine to me.