Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,465,489
Community Members
 
Community Events
176
Community Groups

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! 

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

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

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

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

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.

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

Atlassian Community Events