Use of Velocity Generic Tools in a page decorator

I am trying to use SortTool from Velocity Generic Tools inside a decorator that handles the search results.

The code is:

<div id="search-results-body">

            <ul class="search-results">

                #foreach($searchResult in $sorter.sort($results,

                 <li >
                    $action.newSearchResult($searchResult, $showExcerpts, $queryString)





Where $results is the collection of search results and $sorter is a handle to the Sorter class as explained in SortTool.

But the foreach loop is not executed since nothing is displayed, this is because $sort is null which means that confluence default velocity context don't know about that class.

How can I use those generic tools inside the decorators?

Thank you.

2 answers

1 accepted

3 votes
Answer accepted

I found a solution in case someone need it:

1) install velocity-tools-generic-2.0.jar in confluence/WEB-INF/lib

2) Create a plugin in order to add $sorter to Confluence velocity context:

<atlassian-plugin name="Sorter" key="confluence.extra.sorter">

      Plugin to do sorts in velocity templates and decorators.
    <!-- This version is displayed in the application's Plugin Manager. -->

    <velocity-context-item key="mySorter"
          name="Sorter" context-key="sorter"
          class="" />

Now the search results are ordered descending. I would like to know if there is a cleaner way to do 2), since just doing 1) didn't do, nothing was shown.

Can't get sorttool class to load, please help.

Could not load class:' to 'com.leonizm.confluence.plugins.testp'



I am summing: To use $sorter.sort($results,"lastModificationDate:desc"))

in velocity macros Confluense Admin->User Macros macros in confluense You should

1) install velocity-tools-generic-2.0.jar in confluence/WEB-INF/lib

2) Name xml above as "atlassian-plugin.xml" zip (the only file) it into .jar file (for example sorter.jar) and install it as a usual plugin using Confluense Admin->Plugins .

Awesome, thanks for this!

Thanks Andrey.sorter.jar was working fine with confluence 4.3.Do I need to make changes in order to use the same jar in 5.6.5.After installation of sorter.jar in 5.6.5 it shows an error "This add-on could not be loaded. It has one or more errors that prevent it from being enabled. Refer to the logs for more information.". Can you please help regarding this.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

259 views 2 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you