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,
"lastModificationDate:desc"))


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

                </li>

                #end

            </ul>

        </div>

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

This widget could not be displayed.

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-info>
    <description>
      Plugin to do sorts in velocity templates and decorators.
    </description>
    <!-- This version is displayed in the application's Plugin Manager. -->
    <version>1.0</version>
  </plugin-info>

    <velocity-context-item key="mySorter"
          name="Sorter" context-key="sorter"
          class="org.apache.velocity.tools.generic.SortTool" />
</atlassian-plugin>

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: org.apache.velocity.tools.generic.SortTool' to 'com.leonizm.confluence.plugins.testp'

Thanks,

Leon

This widget could not be displayed.

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
Posted Sep 17, 2018 in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

603 views 8 6
Join discussion

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