Sort List of Strings
Hi,
I am wondering if there is a nice way to sort a list of strings. I want to transform $my_list = ["c", "d", "a", "b"] => ["a", "b", "c", "d"].
I have looked into the Sort Tool, but that seems to only deal with nodes. Is there a nice way to simply do this?
Thanks!
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
| ? | Show this help |
|---|---|
| ESC | Blurs the current field |
Comment Form
| r | Focus the comment reply box |
|---|---|
| ^ + ↩ | Submit the comment |
You can use Command ⌘ instead of Control ^ on Mac
1 Posted by Wing Ming Chan on 10 Apr, 2015 12:23 AM
Hi,
If you are willing to turn the list into a map, it is possible:
#set( $items= [] ) #set( $tmp = $items.add( { "value" : "c" } ) ) #set( $tmp = $items.add( { "value" : "d" } ) ) #set( $tmp = $items.add( { "value" : "a" } ) ) #set( $tmp = $items.add( { "value" : "b" } ) )Wing<ul> #foreach ( $item in $_SortTool.sort( $items, [ "value:asc" ] ) ) <li>$item.value</li> #end </ul>
2 Posted by Nadira Yasmeen on 10 Apr, 2015 01:23 AM
Another way to sort strings is by converting the ArrayList to an Array--then passing that as a sort parameter, for example:
3 Posted by ces55739 on 13 Apr, 2015 02:55 PM
Thanks for the suggestions Wing and Nadira!!
I will be using both of these in the future.
ces55739 closed this discussion on 13 Apr, 2015 02:55 PM.