liam_davison
I'm new here

Sorting a menu generated by the navigation function

Jump to solution

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

0 Kudos
1 Solution

Accepted Solutions
Peter_Jodeleit
Crownpeak employee

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.

Peter

View solution in original post

0 Kudos
6 Replies
Peter_Jodeleit
Crownpeak employee

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.

Peter
0 Kudos

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>

0 Kudos

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.

0 Kudos

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.

Peter
0 Kudos

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.


0 Kudos

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.

Peter
0 Kudos