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!
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
Thank you David! It sure did, and thank you for making it so clear - plug and play. Beautiful! Have a great day!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.