Copied to clipboard

Flag this post as spam?

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


  • Claus Nedergaard 62 posts 104 karma points
    Jan 09, 2013 @ 08:49
    Claus Nedergaard
    0

    media picker adds numbers til file name

    Using the generic media picker and standard getmedia to retrieve contents of a media folder the media picker adds this: 160608611png to the file name.

    I'm on umb 4.11. DAMP is installed btw. 

    <img src="/media/6773/peterbyg.png160608611png"

    Clues anyone?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 09, 2013 @ 08:59
    Chriztian Steinmeier
    0

    Hi Claus,

    Yes - what you're seeing is the text() value of the XML you get from the GetMedia() call (e.g. with <xsl:value-of />), which looks something like this:

    <Image id="1200">
        <umbracoFile>/media/6773/peterbyg.png</umbracoFile>
        <umbracoWidth>160</umbracoWidth>
        <umbracoHeight>60</umbracoHeight>
        <umbracoBytes>8611</umbracoBytes>
        <umbracoExtension>png</umbracoExtension>
    </Image>

     

    To get the values from the XML in an efficient way, do something like this:

    <xsl:template match="/">
        <!-- Make sure an image was picked -->
        <xsl:if test="normalize-space($currentPage/pickerAlias)">
            <!-- Get the XML -->
            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($currentPage/pickerAlias, false())" />
    
            <!-- Process the Image -->
            <xsl:apply-templates select="$mediaNode[not(error)]" />
        </xsl:if>
    </xsl:template>
    
    <!-- Template for an Image -->
    <xsl:template match="Image">
        <img src="{umbracoFile}" width="{umbracoWidth}" height="{umbracoHeight}" />
    </xsl:template>
    
    <!-- Other templates... -->
    <xsl:template match="File | Folder">
        <!-- Do something -->
    </xsl:template>

    Hope that helps :-)

    /Chriztian

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 09, 2013 @ 09:02
    Chriztian Steinmeier
    0

    Just saw that you're using DAMP - if you're usin the "Store full media XML", then you can skip the GetMedia() call and set the mediaNode variable like this instead:

    <xsl:variable name="mediaNode" select="$currentPage/pickerAlias//Image" />

    /Chriztian

  • Claus Nedergaard 62 posts 104 karma points
    Jan 09, 2013 @ 10:19
    Claus Nedergaard
    0

    Actually I'm using the built-in 'old' media picker for this property with this xslt:

    <xsl:variable name="mediaFolderId" select="($currentPage/ancestor-or-self::*/mediaFolderId)" />   
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:template match="/">         
    <xsl:if test="$mediaFolderId != ''">         
    <ul id="scroller">
                 <xsl:for-each select="umbraco.library:GetMedia($mediaFolderId, 1)/Image">
                     <li>
    <xsl:element name="img">
          <xsl:attribute name="src">                                                         
    <xsl:value-of select="umbraco.library:GetMedia($mediaFolderId, 1)/Image"/>
    </xsl:attribute>
    </xsl:element>
           </li> </xsl:for-each>
    </ul>
    </xsl:if>
  • Claus Nedergaard 62 posts 104 karma points
    Jan 09, 2013 @ 10:47
    Claus Nedergaard
    0

    On the media type Image I noticed the [mediaLinks] property - what is that used for?

  • Claus Nedergaard 62 posts 104 karma points
    Jan 09, 2013 @ 11:03
    Claus Nedergaard
    0

    Duh! Feel dumb now!! The reason for the added numbers to the media was I used getMedia and not urlencode.

    Everything is fine now with these lines.

    <xsl:variable name="mediaFolderId" select="($currentPage/ancestor-or-self::*/mediaFolderId)" />
     <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:template match="/">
        <xsl:if test="$mediaFolderId != ''">
             <ul id="scroller">
                    <xsl:for-each select="umbraco.library:GetMedia($mediaFolderId, 1)/Image">    <li>
    <xsl:element name="img"> <xsl:attribute name="src">                                                             
          <xsl:value-of select="umbraco.library:UrlEncode(umbracoFile)"/>
    </xsl:attribute></xsl:element>   </li>   </xsl:for-each>         </ul>
Please Sign in or register to post replies

Write your reply to:

Draft