Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Display random photo attachment from another page and its child pages

Jason George September 23, 2011

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.

TIA!

1 answer

1 accepted

1 vote
Answer accepted
David Peterson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 23, 2011

Hi Jason,

You should be able to use something like this:

{report-variable:Images}
{expanding-reporter:page:attachments|as=Attachment}
  {combining-reporter}
    {local-reporter:@self|source=A page}
    {local-reporter:page:descendents|source=A page}
  {combining-reporter}
  {text-filter:attachment:content type|include=image.*}
{expanding-reporter}
{report-variable}

{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!

David

Jason George September 25, 2011

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

Jeff Peters
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 5, 2017

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?

Jacob Bartlett October 26, 2017

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
TAGS
AUG Leaders

Atlassian Community Events