Copied to clipboard

Flag this post as spam?

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


  • Stig Kulvedrøsten 48 posts 69 karma points
    Jun 27, 2010 @ 01:25
    Stig Kulvedrøsten
    0

    Umbraco 4.5 - umbraco.library:GetMedia doesn't return a value

    I'm updating my xslt files to support the new xml schema i version 4.5 and i ran into a problem with the GetMedia function. I've read in the forums that the /Image/ part is crucial, but it doesn't give me any output.

    <xsl:variable name="picFile" select="$currentPage/largeImageHome"/>

    To debug I write out the vale of picFile. <xsl:value-of select="umbraco.library:GetMedia($picFile, 'false')" />
    Output: /media/8823/pol_forside.jpg55020057806jpg

    When I try to get the umbracoFile value into a src attribute it returns no value.
    <img src="{umbraco.library:GetMedia($picFile, 'false')/Image/umbracoFile}" />

    I'm no xslt expert so I guess I've left something out... Anyone got any suggestions?

  • jaygreasley 416 posts 403 karma points
    Jun 27, 2010 @ 09:44
    jaygreasley
    0

    Hey Stig,

    try

    <xsl:value-of select="umbraco.library:GetMedia(number($currentPage/homeImage), 'false')/Image/umbracoFile"/>

    @leemessenger should get the credit for this really as he sussed it out at CG10

    Jay


  • Stig Kulvedrøsten 48 posts 69 karma points
    Jun 27, 2010 @ 11:07
    Stig Kulvedrøsten
    0

    Thanks for the reply Jay, but this didn't change anything.

    I changed it to <img src="{umbraco.library:GetMedia(number($picFile), 'false')/Image/umbracoFile}" />

    I guess the number() function is casting the $picFile value to a number? But how can I do that when the value of $picFile is '/media/8823/pol_forside.jpg55020057806jpg'

    Stig

     

  • jaygreasley 416 posts 403 karma points
    Jun 27, 2010 @ 12:43
    jaygreasley
    0

    I've probably misunderstood but is $picFile not giving you what you need in this instance then? ie the location of the image file that you can use in the href?

    jay

  • Kim Andersen 1447 posts 2197 karma points MVP
    Jun 27, 2010 @ 15:38
    Kim Andersen
    0

    Hi Stig

    I think that you can do something like this:

    <xsl:variable name="imgUrl" select="umbraco.library:GetMedia($currentPage/largeImageHome, 'false')/Image/umbracoFile"/>
    <img src="{$imgUrl}" />

    The above code should work for you, and return the path to the image in the $imgUrl. Unless you haven't uploaded the image as an image-mediatype. If you have uploaded the choosen image as a File-mediatype, you would change the /Image/ with /File/ or just /*/.

    Hope this helps...

    /Kim A

  • Stig Kulvedrøsten 48 posts 69 karma points
    Jun 28, 2010 @ 14:37
    Stig Kulvedrøsten
    0

    Jay:
    - $picFile give me all the attributes/properties of the image. path, width, height, etc... I want to extract the path to use in the href. This should easily be done using /Image/umbracoFile

    Kim:
    - I totally agree that that should work :) hehe. But unfortunately, it doesnt... The strangest part is that I get the data using umbraco.library:GetMedia($currentPage/largeImageHome, 'false'), but when trying to extract the path it returns nothing.

    I'm doing this work on a project I'm trying to upgrade. Could I have done something wrong during the upgrade? I copied the entire 4.5 folder into my old 4.0.4.1 project and ran the install wizard.

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Jun 28, 2010 @ 14:51
    Peter Dijksterhuis
    0

    If $picFile is allready returning everything, you should not call GetMedia again.

    Just use

    <xsl:value-of select="$picFile/Image/umbracoFile"/>

    If that doesn't work, try a xsl-copy-of select="$picFile" instead of the xsl:value-of. You then can see the complete xml in the source-code of your page. That should be helpfull to determine what the vaule of all xml of the picFile is.

    Peter

  • Stig Kulvedrøsten 48 posts 69 karma points
    Jun 28, 2010 @ 15:01
    Stig Kulvedrøsten
    0

    xsl:copy-of gave me some answers :)

    umbraco.library:GetMedia($currentPage/largeImageHome, 'false') returns:
    <node id="2788" version="bfed13f0-3939-4c9e-bc9a-7f447121f242" parentid="-1" level="1" writerid="1" nodetype="1032" template="0" sortorder="2" createdate="2010-04-15T15:15:57" updatedate="2010-04-15T15:15:57" nodename="Forside_bilde" urlname="forside_bilde" writername="Katinka Odner" nodetypealias="Image" path="-1,2788">
    <data alias="umbracoFile">/media/8823/pol_forside.jpg</data>
    <data alias="umbracoWidth">550</data>
    <data alias="umbracoHeight">200</data>
    <data alias="umbracoBytes">57806</data>
    <data alias="umbracoExtension">jpg</data>
    </node>

    GetMedia returning old schema xml? I guess something isn't upgraded?

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Jun 28, 2010 @ 15:14
    Peter Dijksterhuis
    0

    Looks that way indeed.

    Was this a new installation or an upgrade?

    If it is an upgrade, try deleting the umbraco.config file and then restart the app-pool.

    That should recreate the umbraco.config. After that, see what the result is again.

    Peter

  • Stig Kulvedrøsten 48 posts 69 karma points
    Jun 28, 2010 @ 15:29
    Stig Kulvedrøsten
    0

    It was an upgrade.

    After recreating the umbraco.config file I still got the same problem. Umbraco.config however,  looks like it's using the new schema.

    Is umbraco.config the source umbraco.library:GetMedia() uses? Or is it the GetMedia function who generated the xml that is returned?
    I can't find the media node in umbraco.config.

    Stig

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Jun 28, 2010 @ 15:33
    Peter Dijksterhuis
    0

    Hm, in that case, try re-saving the media-item to see if it will get the new schema.

    I'm not too sure how the media works is handled during an upgrade. Perhaphs someone from the core-team could answer this?

  • Stig Kulvedrøsten 48 posts 69 karma points
    Jun 28, 2010 @ 15:37
    Stig Kulvedrøsten
    0

    Looks like the media-item needed to be re-saved.. Then it works like charm! Thanks alot Peter.

    But this database contains several hundred images, and I cant go re-saving them all :)
    Hopefully someone got a easier fix to this?

  • Peng 41 posts 62 karma points
    Jun 29, 2010 @ 02:58
    Peng
    1

    Hi Stig,

    I got the same issue after upgrading to version v4.5. I deleted the umbraco.config first. ThenI re-saved the media item and even created a new media item, they still follow the old structure for NodeContentXml.

    Is there any step missing here?

    Regards,

    Peng

     

  • Chefdog 5 posts 26 karma points
    Jul 17, 2010 @ 11:44
    Chefdog
    1

    Man the umbraco.library:GetMedia gave me some headaches, all I wanted to loop trough all the images from a media folder

    and display them. I tried the code from the documentation on the wiki, nothing. I found a solution! Oh no upgrade,

    just a basic new install with Umbraco 4.5. The complete info can be found here

    <xsl:if test="$sliderRoot!=''">
    <xsl:for-each select="umbraco.library:GetMedia($sliderRoot, 'true')
    /descendant-or-self::*[@nodeTypeAlias='Image']/umbracoFile">
                    <img>
    <xsl:attribute name="src"><xsl:value-of select="." /></xsl:attribute>
    <xsl:attribute name="alt"><xsl:value-of select="../@nodeName" /></xsl:attribute>
                    </img>
    </xsl:for-each>
    </xsl:if>


  • Sajid Riaz 142 posts 165 karma points
    Jul 18, 2010 @ 13:26
    Sajid Riaz
    0

    Hi Stig,

    I'm trying to get the xml nodes displayed on my page so  I can see the structure.  Not having any luck just yet.

    how did u do that?

                   xsl:copy-of gave me some answers :)

     

    >sajid (xslt new bie)

  • Sajid Riaz 142 posts 165 karma points
    Jul 18, 2010 @ 16:08
    Sajid Riaz
    0

    chefdog, thankyou for the xslt in yr post and yr site.

    >sajid

  • Brad Crandell 4 posts 26 karma points
    Jul 22, 2010 @ 11:49
    Brad Crandell
    0

    I found an answer to this problem over on another post.   It looks like the code

    umbraco.library:GetMedia({0},'false')/data[@alias = 'umbracoFile']

    should be

    umbraco.library:GetMedia({0},'false')/*/data[@alias = 'umbracoFile']

    I was moving some code from a 4.0 site into a fresh install of a 4.5 site and this change worked for me, I hope it works for you, too.

    - Brad

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jul 22, 2010 @ 12:12
    Lee Kelleher
    0

    Hi all,

    So that you are all aware, there was a bug in GetMedia in v4.5 - which meant that you had to include the extra "/*/" bit.  This has been fixed in the upcoming v4.5.1 release.  If you plan on upgrading to v4.5.1 (and you should), then you'll need to revert your XPath changes to GetMedia.

    Cheers, Lee.

  • Stig Kulvedrøsten 48 posts 69 karma points
    Jul 22, 2010 @ 13:17
    Stig Kulvedrøsten
    0

    Thanks Brad! Problem solved :)

    And thanks for info about the bugfix in the upcoming 4.5.1 release Lee. This has been a pain in the *** ;)

    // Stig

  • shweta 4 posts 24 karma points
    Jul 27, 2010 @ 08:33
    shweta
    0

    I am using Umbraco 4.5 and I dont know about xslt. Want to ask that how to display the image using media picker? Whats the code in xslt file? Is it same with the previous versions of umbraco?

  • Sajid Riaz 142 posts 165 karma points
    Jul 27, 2010 @ 13:29
    Sajid Riaz
    0

    hello shweta,

     

    try this:

    ImageLocation is the property on the doc type.  Which is of MediaPicker type.

    in yr contentpage set it point at the media folder containing yr images or the image you want to display.

    <xsl:variable name="imageRoot" select="$currentPage/ImageLocation"/>

    <xsl:template match="/">
      <xsl:variable name="mediaItems" select="umbraco.library:GetMedia($imageRoot, true())"/>
      <xsl:copy-of select="$mediaItems/Image"/>
      <xsl:for-each select="$mediaItems/Folder/Image">
      <xsl:variable name="picFile" select="umbracoFile"/>
        <xsl:variable name="picW" select="umbracoWidth"/>
        <xsl:variable name="picH" select="umbracoHeight"/>
          <img>
              <xsl:attribute name="src"><xsl:value-of select="$picFile"/></xsl:attribute>  
          </img>
    </xsl:for-each>

     

    >sajid

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Jul 27, 2010 @ 17:08
    Nik Wahlberg
    0

    Hi all, I have just upgraded a 4.5 site to 4.5.1 and am still seeing issues with GetMedia. Here's a copy-of from my $media variable (with just the GetMedia() call, no trailing xPath):

    <Image id="1075" version="576bd587-f076-44b0-bec0-eebdfd16cd56"
    parentID="-1" level="1" writerID="0" nodeType="1032" template="0"
    sortOrder="49" createDate="2010-07-27T10:32:18"
    updateDate="2010-07-27T10:32:19" nodeName="Tester" urlName="tester"
    writerName="Administrator" nodeTypeAlias="Image" path="-1,1075">
      <umbracoFile>
      /media/247/img_clintrial_microscope.jpg</umbracoFile>
      <umbracoWidth>201</umbracoWidth>
      <umbracoHeight>135</umbracoHeight>
      <umbracoBytes>7892</umbracoBytes>
      <umbracoExtension>jpg</umbracoExtension>
    </Image>
    

    The following produces no result at all:

    <xsl:variable name="media" select="umbraco.library:GetMedia(current()/newsImage, 0)/Image/umbracoFile" />

    Whereas this (strangely enough consider ing the value of copy-of get media):

    <xsl:variable name="media" select="umbraco.library:GetMedia(current()/newsImage, 1)/umbracoFile" />

    Produces this:

    <umbracoFile>/media/247/img_clintrial_microscope.jpg</umbracoFile>

    What gives? Do others still have this same issue?

    Thanks,
    Nik

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jul 27, 2010 @ 17:15
    Lee Kelleher
    0

    Hi Nik,

    There was a bug in v4.5, which has been fixed in v4.5.1.

    In v4.5 GetMedia was internally pointing at the documentElement - which meant that you had to explicitly put the node's name (i.e. /Image/umbracoFile).

    Whereas in previous version of Umbraco (and now back v4.5.1) the internal pointer was the firstChild ... so you don't need to explicitly reference the node name.

    I think we're gonna have a couple of weeks of confusion, but at least GetMedia is working properly again.

    Cheers, Lee.

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Jul 27, 2010 @ 17:17
    Nik Wahlberg
    0

    Thanks Lee. Perhaps my upgrade didn't work as expected. I'll do a clean install and see what happens. 

    Cheers!

    -- Nik

Please Sign in or register to post replies

Write your reply to:

Draft