Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • trfletch 598 posts 604 karma points
    Dec 15, 2009 @ 15:58
    trfletch
    0

    Add document icon automatically

    Hi all,

    I have an Umbraco V4 website and I have the following code to list some documents (the code lists a link to the document property of a child page). I want to be able to add an icon next to the link such as a PDF or Word icon depending on what type of document it is. I was thinking I could add a couple of IF statements into my code to check what the file extension of the file is but I'm not sure what I need to test for. Can anyone give me any pointers or is this the wrong way to go about this?:

    <xsl:template match="/">
    <xsl:if test="$currentPage/node != ''">

    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
    <xsl:if test="data [@alias='document'] != ''">
    <xsl:if test="TEST FOR PDF EXTENSION">
    <img src="/images/pdf-icon.jpg"/>
    </xsl:if>
    <xsl:if test="TEST FOR WORD EXTENSION">
    <img src="/images/word-icon.jpg"/>
    </xsl:if>
    <a target="_blank" href="{umbraco.library:GetMedia(data [@alias = 'document'], 'false')/data[@alias='umbracoFile']}"><xsl:value-of select="@nodeName"/></a>
    </xsl:if>
    </xsl:for-each>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>
  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 15, 2009 @ 16:17
    Dirk De Grave
    0

    Hi,

    Each media file gets a umbracoExtension property, so you can check for that! Or, if you don't mind using jquery, here's a great example of setting the document icon

     

    Hope this helps.

    Regards,

    /Dirk

  • dandrayne 1138 posts 2262 karma points
    Dec 15, 2009 @ 16:30
  • trfletch 598 posts 604 karma points
    Dec 15, 2009 @ 17:28
    trfletch
    0

    Hi Dirk and Dan,

    Thanks for the repsonses, I have gone with Dirk's suggestion using jquery which works really nicely and from an accessibility point of view these icons are not critical so if someone is using a browser without script enabled then it doesn't really matter that they will not see the icons.

Please Sign in or register to post replies

Write your reply to:

Draft