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

Is There a Macro for Returning a File Type's Icon?

Phillip Ponzer [Cprime]
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.
November 21, 2011

Is there a macro for returning the icon specific to a file's type?

For instance, I notice the attachments macro shows an "MS Excel" icon when an "xls" is attached and an "Adobe Acrobat" icon when a "pdf" is attached. What does that macro use to figure out which icon to display?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
November 22, 2011

You could just use CSS to achieve this e.g.

a[href$='.pdf'] {
    display:inline-block;
    padding-left:20px;
    line-height:18px;
    background:transparent url(/path/to/pdf-icon.png) center left no-repeat;
}

...read more.

Phillip Ponzer [Cprime]
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.
November 22, 2011

Sweet! I just added the styling to my user macro and it worked nicely!

<style type="text/css">
a[href$='.pdf'] {
    display:inline-block;
    padding-left:20px;
    line-height:18px;
    background:transparent url(.../confluence/images/icons/attachments/pdf.gif) center left no-repeat;
}
</style>

0 votes
Remo Siegwart
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.
November 22, 2011

If you are using a user macro and have an $attachment variable available, you could just insert the following line to automatically display the appropriate icon depending on the content type of the attachment:

#parse ("/pages/includes/attachment_icon.vm")

Otherwise you could create a user macro with either one of the following lines:

<span class="icon icon-file-pdf" title="$action.getText("pdf.file")">$action.getText("pdf.file")</span>
<span class="icon icon-file-image" title="$action.getText("jpeg.file")">$action.getText("jpeg.file")</span>
<span class="icon icon-file-excel" title="$action.getText("excel.file")">$action.getText("excel.file")</span>
...

Hope this helps

Phillip Ponzer [Cprime]
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.
November 22, 2011

Very cool! I'm actually looping through a page's attachment list and this works pretty nicely when used for each loop iteration.

#foreach( $attachment in $attachmentsList )
  #parse ("/pages/includes/attachment_icon.vm")
#end

TAGS
AUG Leaders

Atlassian Community Events