how to know the total attachments of a page?

liljoint May 24, 2012

I need to know howmany files attached has a page...

exists any variable for this???

thnx

4 answers

0 votes
MatthewC
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 26, 2012

How do you want to use this variable?

You can display it on a page by writing a user macro & accessing the velocity context.

## Macro title: Attachment download Path
## Macro has a body: N
##
## Developed by: Matthew Cobby matt@andamooka.com


## Get basic manager objects first
#set($attachmentManager=$content.getAttachmentmanager())

## Get the Page manager & the target page
#set($attachmentsList=$attachmentManager.getLatestVersionsOfAttachments($content))
#set($numAttachments=$attachmentsList.size())

Number of Attachments: $numAttachments;

0 votes
Matthew J. Horn
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.
May 25, 2012

The AbstractPage has a getAttachments() method on it that you could probably use. It returns a List. You could then just get the number of items in the List. What little doc there is on the method says "Don't use it directly, use AttachmentManager.getAttachments(page) instead"

According to this page (https://developer.atlassian.com/display/CONFDEV/Confluence+Objects+Accessible+From+Velocity), you can use $attachmentManager to get a reference to the AttachmentManager. The AttachmentManager has a method called countLatestVersionsOfAttachments() that appears to do exactly what you want.

matt

liljoint May 25, 2012

nope, Those options doesn't work... :( I need to know how many attached files have the page, inside the main layout...

0 votes
liljoint May 24, 2012

inside the principal decorator... is there something like $sitemeshPage or anything ???

0 votes
Renjith Pillai
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.
May 24, 2012

Could you explain what you need to achieve? Plugin?

REST API do gives the count of attachments for a page.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events