Search the FirstSpirit Knowledge Base
Hello,
We would like to be able to sort the navigation menu generated by the navigation function. Initially we would like to sort the results alphabetically, but in time other sort orders (such as date created) may also be required.
Is it possible to sort the results of the CMS navigation function?
Many thanks,
Liam Davison
The ordering could be changed in the client. If you want to apply a special ordering you've got to build your own navigation function.
The ordering could be changed in the client. If you want to apply a special ordering you've got to build your own navigation function.
Yes, I've been experimenting with writing my own function, something like this:
$CMS_SET(kids,#global.node.getParentFolder().getChildren().toList())$
<ol>
$CMS_FOR(child,kids.copy.sort(x -> x.findStartNode().getPage().getFormData().get(#global.language,"pt_heading_text").get()))$
$CMS_IF(child.isFolder())$
<li>$CMS_VALUE(child.findStartNode().getPage().getFormData().get(#global.language,"pt_heading_text").get())$</li>
$CMS_END_IF$
$CMS_END_FOR$
</ol>
Another approach would be to use the navigation function, but to just all matching entries to a (java) list instead of writing out html snippets. Then you could implement a Comparator to implement your sorting.
Should be easier than doing everything manually.
Possible, but normally you output multiple levels, then sorting the result as a simple list is no longer possible (because it's a tree). Therefore I think a template fragment which is called recursivly is more appropriate.
How do I put the navigation entries into a Java list? As far as I understand, the navigation function returns an object of class de.espirit.firstspirit.generate.functions.NavigationFunctionImpl$PathOnlyNavigation which isn't documented in the public API.
You can't do this. As you say, this is an internal object and the only thing you can do with this is to use in in a $CMS_VALUE construct.
When I said "build your own navigation function" I meant without using the provided navigation function at all.