how to know the total attachments of a page?

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

exists any variable for this???

thnx

4 answers

Could you explain what you need to achieve? Plugin?

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

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

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

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

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;

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

2,856 views 27 11
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you