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

Josh Kwan June 10, 2013

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
Rodrigo Girardi Adami
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 18, 2013

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

1 vote
Matthew Beda March 20, 2019

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>

Fabienne Gerhard
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 26, 2020

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! 

Matthew Beda December 14, 2022

If you attached it to the top level Home page it should parse down through the other pages.

0 votes
Gustavo Segura April 15, 2020

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

Matthew Beda October 30, 2020

If you don't want the heavy load of the attachments macro you could use a user macro like this that just creates a UL of attachments on a page. You could the utilize the Page properties macro like @Gustavo Segura mentioned

## @noparams
<style>
ul.sreattachmentul {
padding: 0;
margin: 0;
list-style: none;
}

ul.sreattachmentul li a .aui-icon {
top: 3px;
padding-right: 8px;
}

ul.sreattachmentul li .footnote {
font-size: 12px;
color: #9d9d9d;
}

ul.sreattachmentul a {
padding-right: 10px;
}
</style>
#set ($attachmentsList = $content.getLatestVersionsOfAttachments())
#if ($attachmentsList.size() > 0)
<ul class="sreattachmentul">
#foreach( $attachment in $attachmentsList )
#set ($currentAttachmentId = $attachment.id)
#set($AttachmentSize = $attachment.getFileSize() / 1000)
<li>
<a href="$generalUtil.htmlEncode("${req.contextPath}${attachment.downloadPathWithoutVersion}")">
<span class="aui-icon aui-icon-small aui-iconfont-file-generic">File</span>
$generalUtil.htmlEncode($attachment.fileName)
</a>
<span class="footnote"><span>$attachment.creator.name</span> - <span>$AttachmentSize kb</span></span>
</li>

#end
</ul>
#end

Gustavo Segura October 30, 2020

We're using cloud, unfortunately no user macros for us...

Deniz December 7, 2022

Hello. As I understand it, all these custom macros are only for displaying attachments of one page. and how to display the attachments of the parent page and its child pages, without resorting to the use of labels?
Labels for each attachment is very inconvenient.

Ideally: on the parent page, we put a macro that displays all the attachments of this page + the attachments of its child pages.

Matthew Beda December 8, 2022

Please look at my previous post for March which pulls in all the attachments based on the define page as ancestorid. If you combine this with either embedding the atlassian attachment macro markdown or with a my other post on October you should be able to figure out a way to get the desired results. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events