It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Is there an attachment list macro that can show all attachments for child pages?

Hi,

I'd like to be able to show an attachment list on a page and specify the root (e.g. "@self") and have the list macro show all attachments beneath the specified root key.

The Attachment List and View Files macros don't appear to have this ability. Any ways to do this? I do have the Reporting Plug-in if that's a possibility.

Thanks!

4 answers

1 accepted

3 votes
Answer accepted

Hi Josh,

I did some searches here and I think this is not possible at the moment. I could find a feature request open for this which I suggest you to vote on: https://jira.atlassian.com/browse/CONF-11968

I hope this helps!

Regards,

Rodrigo

Work in Progress

## @Param page:title=Page|type=confluence-content|required=true|desc=Select a page to use
## @Param DefaultView:title=Default View for Panels|type=enum|default=none|enumValues=none,block|desc=Block to show open by default, None to show Closed by default
## @Param filestypestoexclude:title=File types to Exclude|type=string|required=false|desc=File types to exclude are space delimited and should be preceded with a "-" ......example (-png -bmp) for all use "-none"

##########################
## Get the page manager ##
##########################
#set( $containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager') )
#set( $getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null) )
#set( $containerManager=$getInstanceMethod.invoke(null,null) )
#set( $containerContext=$containerManager.containerContext )
#set( $pageManager=$containerContext.getComponent('pageManager') )

####################################
## Get the page ##
####################################
#set( $i = 0 )
#set( $len = 0 )
#set( $key = "" )
#set( $name = "" )
#set( $parts = $parampage.split(":") )
####################################
## Find the length/size of $parts ##
####################################
#foreach( $part in $parts )
#set( $len = $len + 1 )
#end
#if( $len == 1 )
#set( $key = $content.spaceKey )
#set( $name = $parampage )
#else
#foreach( $part in $parts )
#if( $i == 0 )
#set( $key = $part )
#set( $i = $i + 1 )
#else
#set( $name = $part )
#end
#end
#end
#set( $page = $pageManager.getPage($key, $name) )
<style>
.SRPG .searchMacro .resultSummary {
display: none;
}

.SRPG .searchMacro a + .smalltext,
.SRPG .searchMacro a + .smalltext a {
color:#a5a5a5;
}

.SRPG .searchMacro .result span + a {
font-size: 18px;
}
.SRPG .searchMacro {
color:#fff;
line-height:0;
}
.SRPG .searchMacro a,
.SRPG .searchMacro span {
line-height:22px;
}
.SREATTITLE {
color: #65aad4;
font-size: 15px;
line-height: 18px;
font-weight: 400;
text-transform: uppercase;
border-bottom: 1px solid #ccc;
padding: 4px;
cursor: pointer;
}
.SREAttachmentsPage {display:none;}
.SREAttachmentsPage .result {
margin-left: 14px;
border-left: 3px solid #ccc;
margin-top: 0px;
padding-top: 9px;
}

.SREAttachmentsPage +.SREAttachmentsPage {
margin-top: 19px;
}
</style>
<script type='text/javascript'>
AJS.toInit(function(){
AJS.$('.SRPG a + .smalltext a:last-child').each(function(){
var textTrim = AJS.$(this).text();
var Results = AJS.$(this).closest('.result');
AJS.$(Results).attr('group-Title', textTrim);
textTrim = textTrim.replace(/[\W_]+/g, '');
AJS.$(this).closest('.result').addClass('SRPGgrouped').addClass(textTrim);
var Results = AJS.$(this).closest('.result');
});
AJS.$('.SRPG .SRPGgrouped').each(function(){
var class2 = AJS.$(this).attr('class');
class2 = class2.split(' ')[2];
if (!AJS.$('.SREAttachmentsPage.' + class2).length){
AJS.$('.' + class2).wrapAll("<div class='SREAttachmentsPage " + class2 + "' style='display: $paramDefaultView;'></div>");
var Title = AJS.$('.SREAttachmentsPage.' + class2 +' .result:first-child').attr('group-title');
AJS.$('.SREAttachmentsPage.' + class2).before('<div class="SREATTITLE">'+Title +'</div>');
}
});
AJS.$('.SREATTITLE').click(function(){
AJS.$(this).next('.SREAttachmentsPage').toggle();
});
});
</script>
<div class=SRPG>
<ac:structured-macro ac:name="search" ac:schema-version="1" ac:macro-id="31b370cc-1a06-4bf5-bea6-61250a6f5bf3">
<ac:parameter ac:name="query">ancestorIds:$page.id $paramfilestypestoexclude</ac:parameter>
<ac:parameter ac:name="type">attachment</ac:parameter>
</ac:structured-macro>
</div>

Hi @Matthew Beda 

thanks for this cool code for a macro! It works fine for me. Just had to change 

## @Param into @param

to make it work. 

Do you see any chance make it work for spaces instead of one page? That would be overwhelming awesome. Thanks in advance! 

This is pretty old but found a workaround that might work for others, it is not super elegant...

Given we have the following structure:

page

  • sub page
  • sub page
    • sub page
    • attachment
  • sub page
    • attachment
    • attachment

Lets say we want to display all subpage attachments in the main page. What we did was created a template for the sub pages, which uses the page properties and adds a label to all sub pages.

Under the macro, we have one column that will display the page attachments macro.

In the main page we generate a page properties report with the column that has the attachments macro for the subpage. 

 

Main page looks like this...I removed some info so it looks kinda weird, but you guys get the point :)

Untitled.jpg

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

Lessons and Learnings: Six Months of Working Remote [Discussion]

Hey there, folks! For most of us, the past six months- yes, you read that right- have been a journey. More people than ever before have pivoted to working remotely, and navigating being on-scre...

5,965 views 4 6
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you