Show images (attachments) on a page, based on the labels on that page

Mads Haugaard
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!
September 9, 2022

Hi.

Is there a way to show specific images (attachments) based on the labels on a page?

It needs to be based on the labels on the specific page, NOT the images them selfs.

Anyone know of a way?

1 answer

0 votes
Andrii Maliuta
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 9, 2022

Hello @Mads Haugaard ,

As I know, this is NOT possible with platform macros, but this should be easy code to implement a custom macro or using a ScriptRunner script to get the list of such pages.

Example for a space pages with label 'TEST':

SpaceManager spaceManager = ComponentLocator.getComponent(SpaceManager.class);
Label label = new Label("TEST");
Space space = spaceManager.getSpace("SPACE_A");
List<Page> spacePages = space.getAllPages;
List<Attachment> attachments = new ArrayList<>();
spacePages.filter(page -> page.gtLabels().contains(label)).forEach(page -> {
List<Attachment> pageAttaches = page.getAtatchment();
attachments.addAll(pageAttaches);
});

return attachments;

 

Thanks

Mads Haugaard
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!
September 9, 2022

Thank you for the answer.

What I need is the som way to show images based on the labels on a page.

 

Ex.

A page has a label named "sunshine".

That page also has an attachment (image) named "sunshine.jpg" with the label "sunshine".

That image is automatically show on the above mentioned page.

If the label is removed from the page, then the image is no longer show.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events