Display random photo attachment from another page and its child pages

Trying to grab a random attachment from a photo gallery page - located on a child page, uses the gallery macro - and it's child-pages (the sub-albums).

First, I'd love to know if there's a better way for managing a photo gallery in Confluence.

Second, and my main question, how do I do this? I found a code example using the report-image macro but can't get it to work:

- Home page

- - W page (this is the page I want to display a random image on)

- - - X page (page containing various content, DON'T WANT to get anything from this)

- - - A page (this is a gallery page, may get a random photo/attachment from here)

- - - - B page (sub/child-page of A, could also get random photo from here)

- - - - C page (as B)

- - - - D page (as B)

- - - Y page (another page, don't want to get anything here!)

- - - Z page (as Y)

In short, get random image (attachment) from A, B, C, or D and display on W - but don't get anything from X Y Z or anywhere else in the space.


1 answer

1 accepted

This widget could not be displayed.

Hi Jason,

You should be able to use something like this:

    {local-reporter:@self|source=A page}
    {local-reporter:page:descendents|source=A page}
  {text-filter:attachment:content type|include=image.*}

{report-image:variable:Images > query:as collection > collection:random > expanded:Attachment > attachment:url}

Essentially, it creates a combination list of 'A page' (@self) with the descendants of 'A page' (yes, 'descendents' is spelled that way in the supplier. It's a typo I should fix in the code sometime...). Then, it expands on the attachments of said pages that have a content type starting with 'image'. So, we end up with a big list of all attachments, stored in 'expanded' objects. Then, we select a 'random' item from the complete list and grab it's URL for the {report-image}.

Hope that helps!


Thank you David! It sure did, and thank you for making it so clear - plug and play. Beautiful! Have a great day!

This sounds like exactly what I'm trying to accomplish, but unfortunately I'm too much of a non-coder to understand what to do with this. Do I use this code to create a User Macro?

This doesn't work for me - I'm trying to place the macro in a panel if that's relevant. I'm just pasting in the macro you wrote, changing the page names. Do you know what I can change? 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday 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...

155 views 2 4
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