Is there any way to link to a random page in confluence like in media wiki? Can't find a macro/plugin for that. I don't have the reporting plugin. Does anyone have a little JS for that for a user macro? Thanks in advance, Stefan

7 answers

1 accepted

If this doesn't work out, you can write a macro to do it, but you'll need to do a bit of work to get it going:

1) Add the org.apache.velocity.tools.generic.MathTool class to the Velocity context (this is so you can generate a random number in your macro) -- instructions are here (you'll need to modify the XML file to get the Math class rather than the Sorter that the instructions use): https://answers.atlassian.com/questions/62575/use-of-velocity-generic-tools-in-a-page-decorator

2) Create the macro:

a) Get a count of how many pages are in the space.

b) Generate a random number between 0 and the count.

c) Use some logic to get the page at the index matching your random number (one way to do this is to call getSortedChildren() on the root page of the space. This returns a List of Pages. Then get the page with the Lists class's get() method, which takes an index.

d) Use Page class's getUrlPath() method (or maybe you can do it with just getDisplayTitle()) to add a link to the page (I think this will do it, but there's no doc for that method, so I'm not sure).

1 vote
Daryl Chuah Atlassian Team Apr 27, 2013

Hi Stefan

Perhaps you can have can refer on HTML Include Macro documentation for more information.

Hope it helps!

Cheers :)

Thanks for your answer, but how to get a random page with HTML Include? I have to provide a URL for this macro.

If I understand you correctly, you want a function that randomly selects a page from the Confluence database and displays it to the user. For example, you might have a Space that contains help for your company --- so you might randomly want to show these to users when the login --- sort of like a revolving splash page in a GUI.

Confluence doesn't have the equivalent. You could possibly quickly write a user macro that did this.

Hallo Stefan

There used to be a plugin that supplied a "random include" macro, but that plugin is no longer available. What I have found is the Java source of the original plugin that supplies the macro: https://svn.atlassian.com/svn/public/contrib/confluence/include-random-plugin/trunk/src/main/java/com/macadamian/confluence/macros/includerandom/IncludeRandom.java

At the top of that file are the names of the developers. It may be worth contacting them to see if they plan to update the macro to work in later versions of Confluence.

I hope this gets you some of the way there!

Cheers, Sarah

If I understand you correctly, you want a function that randomly selects a page from the Confluence database and displays it to the user. For example, you might have a Space that contains help for your company --- so you might randomly want to show these to users when the login --- sort of like a revolving splash page in a GUI.

Confluence doesn't have the equivalent. You could possibly quickly write a user macro that did this.

Hello Mary, Hello Sarah,
thanks for the help. I'll try to contact the developers.

Have a nice Weekend, many greets from germany

Stefan

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

606 views 20 11
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