How to use Velocity to pull an image into a confluence user macro? Edited

Hi,

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?

Thanks

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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Meet the AUG leaders of Northern Virginia

@Rachel Wright (Jira Genie), @Billy Poggi (AUG NOVA, DC), and @Dana Jansen (Confluence Queen) are just some of the folks that lead one of the world's most active Atlassian User Group (AUG)....

125 views 4 9
Read article

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