Copied to clipboard

Flag this post as spam?

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


  • Adi 79 posts 183 karma points
    Jan 18, 2014 @ 13:04
    Adi
    0

    Umbraco, adding attachments to articles in back-end and then showing them in front-end CMS

    Hello,

    On my Umbraco website, I have the section which shows latest News. Each news is one article.

    Unfortunately, I can't add any attachments to any News article in back-end so users could see that attachment(s) on front-end of website and download them if they want to. This is how I it should look like

    example

    Is this possible to do? While I was using Joomla CMS it was very easy by installing additional module/component which took me only 15 minutes to set.

    Any help is appreciated and many thanks in advance for prompt replies! Adi

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 19, 2014 @ 05:21
    Fuji Kusaka
    0

    Hi Adi,

    From the picture you posted i assume you want to display a list of pdf from a media folder. What you can do is add a newDataType Media Picker "mediaFolderId" to your docType.

    Under settings section go to your Media Type and whatever Media your are using to upload the pdfs. For example "File". Add a newDataType with alias "umbracoBytes" with type Label.

    Since you are using xslt here is the code.

       <xsl:output method="xml" omit-xml-declaration="yes"/> 
    <xsl:param name="currentPage"/>
    <xsl:variable name="mediaFolderId" select="number($currentPage/mediaFolderId)" />
    <xsl:template match="/">
    <!-- Displays all images from a folder in the Media Library -->
    <xsl:if test="number($mediaFolderId)">
    <ul>
    <xsl:for-each select="umbraco.library:GetMedia($mediaFolderId, true())/File">
    <xsl:variable name="size" select="./umbracoBytes" />
    <xsl:variable name="sizeAndSuffix">
    <xsl:choose>
    <xsl:when test="$size &gt;= 1048576">
    <xsl:value-of select="format-number($size div 1048576,'#,###')"/>
    <xsl:text> MB</xsl:text>
    </xsl:when>
    <xsl:when test="$size &gt;= 1024">
    <xsl:value-of select="format-number($size div 1024,'#,###')"/>
    <xsl:text> KB</xsl:text>
    </xsl:when><xsl:when test="$size &gt;= 1024"> <xsl:value-of select="format-number($size div 1024,'#,###')"/> <xsl:text> KB</xsl:text> </xsl:when> <xsl:when test="$size &gt; 0 and $size &lt; 1024"> <xsl:value-of select="format-number($size div 0,'#,###')"/> <xsl:text> Bytes</xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>0 Bytes</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:if test="umbracoFile !=''"> <li> <a href="{umbracoFile}" target='_blank'> <xsl:value-of select="@nodeName"/> []&nbsp;<xsl:value-of select="$sizeAndSuffix"/> </a> </li>
    </xsl:if> 
    </xsl:for-each>
    </ul>
    </xsl:if> 

    Hope this helps

     

    //fuji

  • Adi 79 posts 183 karma points
    Jan 24, 2014 @ 22:30
    Adi
    0

    Hello Fuji,

    thank you very much for your reply, it was helpeful.

    However, in the meantime I have find the solution here

    http://our.umbraco.org/forum/using/ui-questions/47616-Adding-attachments-to-articles-in-back-end-and-then-showing-them-in-front-end-CMS

    Thank you, Adi

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 25, 2014 @ 10:08
    Fuji Kusaka
    0

    Hey Adi,

    Good to know you finally got it working but in razor instead of xslt at the end.

    Anyways the end results is the most important and where you feel more comfortable/

    Glad i could help

    //Fuji

Please Sign in or register to post replies

Write your reply to:

Draft