Copied to clipboard

Flag this post as spam?

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


  • Bob Jones 33 posts 54 karma points
    Dec 21, 2011 @ 12:21
    Bob Jones
    0

    Failed to load given URL - img src

    I am following Tim's video tutorial on Using Content and Media Pickers. I have reached the part of the tutorial where I have to set the image source to the path returned by get media.

    I have followed Tim's example:

    <img src="{umbraco.library:GetMedia($currentPage/mediaItem, 'false')}" />

    But when I load the page it says 'error reading xslt file'. I then tried to follow the examples on the new schema by Warren Buckley, as linked to here http://our.umbraco.org/wiki/reference/xslt/45-xml-schema/xslt-examples-updated-to-new-schema and came up with this:

     <h2Path </h2>
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/mediaItem, 'false')"/>
      <xsl:variable name "imgSrc" select="umbraco.library:GetMedia($currentPage/mediaItem, 'false')" />
      <h2Image </h2>
      <img src="$imgSrc"/>

      The page loads without the error message for this but the image does not load. When I inspect the element in chrome a tooltip message next to the variable '$imgSrc' gives the following message: "Failed to load given URL"

    Also, in case it is relevant, the path returned by the get media shows as follows: 

    ~/media/528/122011_1710_Myrubbishne2.jpg1280960166169jpg

    Any help appreciated

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Jan 25, 2012 @ 16:58
    Lee Kelleher
    0

    Hi Bob,

    I wrote a blog post about using GetMedia a while ago. [link]

    The common misconception of using the GetMedia function is that it will return the image path - instead it returns an XML document that contains all the properties of that media item.

    My advice for "best practise" is to follow how I use GetMedia in my blog post - as in, testing each part as a value (in order to prevent any errors)

    However if you would like a single line to copy-n-paste, use this:

    <img src="{umbraco.library:GetMedia($currentPage/mediaItem, 0)/umbracoFile}" />

    Cheers, Lee.

  • ankush 2 posts 21 karma points
    Jun 19, 2013 @ 13:45
    ankush
    0

    hi Lee Kelleher,

    I have made a website in umbraco. i first created it in turkish language then i copied that node in content node and set a new hostname for that. so now my site is in two languages. But after i have converted my site into multilingual site, i am having problem in rendering image. I am using getMedia method to render image, but images renders some times and some times i got empty src. I have searched a lot on net but i did not find any solution. I am posting my code.  Please help me.

    My site url is http://www.wedclassis.com/en/magonline/

    code

     <ul class="books">

    <xsl:for-each select="$currentPage//Book">

    <li>

    <h3><xsl:value-of select="@nodeName" /></h3>

    <xsl:variable name="bookImage" select="umbraco.library:GetXmlNodeById(@id)/bookImage" />

    <!--1<xsl:value-of select="umbraco.library:GetMedia($bookImage,'false')/umbracoFile" />

    2<xsl:value-of select="umbraco.library:GetMedia($bookImage,0)/umbracoFile" /> -->

     <a href="{umbraco.library:NiceUrl(@id)}">

    <xsl:choose>

    <xsl:when test="$bookImage &gt; 0">

    <!-- <textarea><xsl:copy-of select="$bookImage" /></textarea> -->

    <xsl:variable name="img1" select="umbraco.library:GetMedia($bookImage,'false')/umbracoFile" />

    <xsl:variable name="img2" select="umbraco.library:GetMedia($bookImage,0)/umbracoFile" />

    <xsl:choose>

    <xsl:when test="$img1!= ''">

    <img src="{$img1}" alt="" style="display: block;" />

    </xsl:when>

    <xsl:otherwise>

    <img src="{$img2}" alt="" style="display: block;" />

    </xsl:otherwise>

    </xsl:choose>

    </xsl:when>

    <xsl:otherwise>

    <img  alt="" style="display: block;" src="http://www.sunqld.com/libr/data/busisale_e/1369089779/noImage.jpg" />

    </xsl:otherwise>

    </xsl:choose>

     

    </a>

    </li>

     

    </xsl:for-each>

    </ul>

    I posted my question here beacuase i did not find the link through which i can ask a new question.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies