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

After I've spend all day working with TMPL_EACH, I'm impressed...

One feature missing is the ability to "sort by keys" when we use TMPL_EACH.

Is this possible?

  • Comment on Re: HTML::Template::Compiled - TMPL_EACH

Replies are listed 'Best First'.
Re^2: HTML::Template::Compiled - TMPL_EACH
by tinita (Parson) on Sep 05, 2008 at 23:20 UTC
    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.

      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