[CONF] How to use Velocity to pull an image into a macro?


I'm writing a macro and I want to pull in an image attached to a page that follows a regular pattern. I.e., I'm trying to pull in an image called 'clientlogo.gif' that is always attached to a page following the pattern of https://[baseurl]/display/[client name]/[client name]/clientlogo.gif.

I figure I have to use $attachmentManager but I'm not sure how to use it. Can anybody help?


1 answer

Looks like AttachmentManager is the class to use. Have you peeked at the API? http://docs.atlassian.com/atlassian-confluence/latest/com/atlassian/confluence/pages/AttachmentManager.html

The first thing I would try is the getAttachmentDownloadPath() method, which should be what the IMG tag wants...

Thanks, Matt, but I'm terrible at reading their API docs so I don't know how I would use it. Am I write in thinking it would be something like $attachmentManager.getAttachmentDownloadPath(clientlogo.gif,$paramclientname/$paramclientname) ?

Now that I think about it, since you know the location of the page, and the name of the file, you don't need to use the attachment manager. You just need the client name. Let's assume the client name is set as $clientName. Then you just do:

<img src="https://$baseUrl/display/$clientName/$clientName/clientlogo.gif"/>

Does that work?

No, it doesn't. The problem is that the way attachments are handled the URLs are structured like this: https://$baseUrl/download/attachments/$pageId/attachment.ext. So that's fine if you're going to use the same resource each time but when you need to reference another page, you're screwed.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,338 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot