Copied to clipboard

Flag this post as spam?

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


  • Tim Arnold 19 posts 39 karma points
    Aug 03, 2010 @ 23:00
    Tim Arnold
    0

    Using XSLT to retrieve an image (Media Pciker etc)

    Hi all, in a similar vein, I have been using this inline XSLT to retrieve and display an image

    <umbraco:Item runat="server" field="headImage" xslt="concat('&lt;img src=&quot;', umbraco.library:GetMedia({0},'true')/ data[@alias='umbracoFile'], '&quot; /&gt;')" XsltDisableEscaping="true" />

    headImage is a parameter set in the document type ie it's a Media Picker

    For one of my development sites it works, for localhost it works, but on my other development site, it doesn't.  Any thoughts?

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 03, 2010 @ 23:05
    Lee Kelleher
    0

    Which version of Umbraco are you using?

    If its v4.5.1+ then the XSLT syntax is wrong, try this:

    <umbraco:Item runat="server" field="headImage" xslt="concat('&lt;img src=&quot;', umbraco.library:GetMedia({0}, 0)/umbracoFile, '&quot; /&gt;')" XsltDisableEscaping="true" />

    If it's 4.5.0 ... then upgrade, as there was a bug in GetMedia in that version - which is fixed in v4.5.1!

    Cheers, Lee.

  • Tim Arnold 19 posts 39 karma points
    Aug 03, 2010 @ 23:07
    Tim Arnold
    0

    Lee

    Version 4.0.3

  • Tim Arnold 19 posts 39 karma points
    Aug 03, 2010 @ 23:08
    Tim Arnold
    0

    Lee, to be precise

     

    umbraco v 4.0.4.2 (Assembly version: 1.0.3811.17115)

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 03, 2010 @ 23:08
    Lee Kelleher
    0

    Hi Tim,

    What happens if you just output the 'headImage' field? Is it the correct Media id?

    <umbraco:Item runat="server" field="headImage" />

    Cheers, Lee.

  • Tim Arnold 19 posts 39 karma points
    Aug 03, 2010 @ 23:13
    Tim Arnold
    0

    Lee

    The Node ID is outputed

    On the 'working site' I get the image in the Node

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 03, 2010 @ 23:17
    Lee Kelleher
    0

    ...and does the site that it doesn't work on have a Media node with that ID? (just need to double-check ... its always the little things that catch us out!)

    If the Media node does exist, try this crude bit of 'debugging'...

    <xmp>
        <umbraco:Item runat="server" field="headImage" xslt="concat('&lt;img src=&quot;', umbraco.library:GetMedia({0}, 0), '&quot; /&gt;')" XsltDisableEscaping="true" />
    </xmp>

    It will output the XML that is returned from GetMedia.  If you could copy-n-paste that here ... or a screengrab is fine. We can see what the problem is.

    Cheers, Lee.

  • Tim Arnold 19 posts 39 karma points
    Aug 03, 2010 @ 23:21
    Tim Arnold
    0

    Lee

    Where 'should' the XML output (I not you are using X<P opening and closing tags

  • Tim Arnold 19 posts 39 karma points
    Aug 03, 2010 @ 23:25
    Tim Arnold
    0

    Lee

    Ok, here is the grab of the site with no image rendering, followed by the site where the image is rendered

    Now where image renders

  • Tim Arnold 19 posts 39 karma points
    Aug 03, 2010 @ 23:27
    Tim Arnold
    0

    Lee

    Note that the Node IDs are and I expect to be different as the sites are on two differing hosts...

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 03, 2010 @ 23:36
    Lee Kelleher
    0

    Hi Tim,

    I'm getting confused between your environments/websites.  First the broken site returned a media ID of 1073, then in the HTML source the ID is 1069?

    I'm still thinking that the media node doesn't exist on the problem website.

    The syntax that you originally posted worked fine on your development website, so its not the code/syntax that's the problem - its that it can't find the media node with that ID?

    - Lee

  • Tim Arnold 19 posts 39 karma points
    Aug 03, 2010 @ 23:38
    Tim Arnold
    0

    I chose a different Page (the site - broken is www.risktecsolutions.co.uk), the site working is www.eyetronics.co.uk

    Both are development sites...

  • Tim Arnold 19 posts 39 karma points
    Aug 03, 2010 @ 23:46
    Tim Arnold
    0

    This is the code from the site that doesn't render

    <div id="divTitleLogo">
            <a href="/home.aspx"><img src="/media/49/blackravLogo.jpg" alt="Black Raviloi Logo" /></a>&nbsp;   
            <umbraco:Item runat="server" field="headImage" xslt="concat('&lt;img src=&quot;', umbraco.library:GetMedia({0},'true')/ data[@alias='umbracoFile'], '&quot; /&gt;')" XsltDisableEscaping="true" />
        <umbraco:Item runat="server" field="headImage" />
        <xmp>
                <umbraco:Item runat="server" field="headImage" xslt="concat('&lt;img src=&quot;', umbraco.library:GetMedia({0}, 0), '&quot; /&gt;')" XsltDisableEscaping="true" />
        </xmp>       
        </div><!-- end of divTitleLogo -->

    Code from site that does (without the 'extra' headImage bit.  Could it be the nesting of the folders where the 'media' is?

    <div id="divTitleLogo">
            <a href="/home.aspx"><img src="/media/images/blackraviolilogo.jpg" alt="Black Raviloi Logo" /></a>
            <umbraco:Item runat="server" field="headImage" xslt="concat('&lt;img src=&quot;', umbraco.library:GetMedia({0},'true')/ data[@alias='umbracoFile'], '&quot; /&gt;')" XsltDisableEscaping="true" />
        <xmp>
                <umbraco:Item runat="server" field="headImage" xslt="concat('&lt;img src=&quot;', umbraco.library:GetMedia({0}, 0), '&quot; /&gt;')" XsltDisableEscaping="true" />
        </xmp>
        </div><!-- end of divTitleLogo -->

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 03, 2010 @ 23:54
    Lee Kelleher
    0

    Hi Tim,

    I don't want to sound like a stuck record, but could you check if the media node for ID 1064 does exist on the risktecsolutions.co.uk site, please?

    Go to the Media section in the Umbraco back-office and hover-over the media node - it should show the ID your browser's status bar.

     

    Everything else in your template appears to be fine.

    Thanks, Lee.

  • Tim Arnold 19 posts 39 karma points
    Aug 04, 2010 @ 00:01
    Tim Arnold
    0

    Lee

     

    I can confirm that Node ID 1064 exists on the Host associated with risktecsolutions.co.uk, as do all the other nodes...

    Could it be the way I uploaded the zip of the images???

  • Tim Arnold 19 posts 39 karma points
    Aug 04, 2010 @ 00:08
    Tim Arnold
    0

    Lee

     

    I've just deleted all media, reinstalled and still Nowt !

    So I now have all new Node IDs eg Node 1105 (looking at the back-office) shows it contains the image 'bigfootbanner.jpg'  I can hard code the node and get the image, so it exists, also FTP'ind shows the Node and Image (for some reason I can't insert an image here now)

    Tim

  • Tim Arnold 19 posts 39 karma points
    Aug 04, 2010 @ 00:37
    Tim Arnold
    0

    Lee

    This might or might not help !

    In the 'flaky' site, I have had to point to the exact URL to get the static image

    ie <img src="/media/1129/blackravlogo.jpg" alt="Black Raviloi Logo" />

    Where 1129 is the Node ID and an actual folder

    On the 'fuctioning site' (not the jpg are different names - I made a mistake in uploading) I can hard code just using the 'images' folder

    ie <img src="/media/images/blackraviolilogo.jpg" alt="Black Raviloi Logo" />

    In both Back-Office set-ups I created a folder 'images' in the Media Content

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 04, 2010 @ 00:46
    Lee Kelleher
    0

    Hi Tim,

    The path of the image (uploaded via the Media section) wouldn't contain the nodeId as the folder.  That number is the database ID from the cmsPropertyData table - it does has caused some confusion with newcomers.

    I'd say hardcode the URL to the image for this instance.  I'm not sure what it could be - if the media node is there, and the template syntax is correct, then it should work - like it has on the other environments/websites.  Bit strange, but difficult to resolve without seeing the back-office set-up.

    Cheers, Lee.

  • Tim Arnold 19 posts 39 karma points
    Aug 04, 2010 @ 00:52
    Tim Arnold
    0

    Lee

    As you can see from the 'working site. I want to change the banner image for each 'different' page.  Was passing the 'headImage' parameter in the document type as a means of doing this.  So I guess I'll have to hard code each banner image in each page - why does it work great on two Hosts and not the other gets me !

  • Tim Arnold 19 posts 39 karma points
    Aug 04, 2010 @ 08:56
    Tim Arnold
    0

    Lee

    I've connected to the SQL dB using SQL Developer (on MAC) for the site that does not render the image using XSLT.  Here is a 'snippet' of the cmsPropertyData table showing Node IDs and the images contained...  If any issue, the 'duff' site was installed via PLESK (Storm Internet), while the funcitoning one(s) used a Web App Gallery Installer (SEEKDOTNET) and my Localhost(ed) account..

     

  • Thomas Egebrand Gram 63 posts 138 karma points
    Feb 03, 2011 @ 17:07
    Thomas Egebrand Gram
    1

    Most wonderful answer for the 4.5, concerning the inline xlst Lee Kelleher!

    Been searching ages around google in order to find a proper answer for 4.5, as there don't seem to be much documentation on how to use the media picker without a macro.

    Good job! I'd highfive you if i could!

     

    Best regards,

    Thomas Egebrand Gram

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Feb 03, 2011 @ 17:20
    Lee Kelleher
    0

    Hi Thomas, you're welcome!  A virtual high-5 works for me! :-D

    Cheers, Lee.

Please Sign in or register to post replies

Write your reply to:

Draft