Copied to clipboard

Flag this post as spam?

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


  • Roger Hughes 55 posts 88 karma points
    Feb 23, 2010 @ 15:30
    Roger Hughes
    0

    Images from media into xslt

    Hi all,

    I am trying to pull back images in a xsl loop from the media folder. My issue is that Umbraco generates random folder names.

    How do I write the value of the image into my xsl document?

    Heres what I have on page at the moment:

    <img src="/media/{data [@alias = 'hostelImage']}.jpg" alt="" title="" />

    This obviously pulls back:

     <img src="/media/1277.jpg" alt="" title="" />

    Any help would be great!

    Thanks

    Rog

  • dandrayne 1138 posts 2262 karma points
    Feb 23, 2010 @ 15:36
    dandrayne
    102

    Have a look at this ->  http://blog.leekelleher.com/2009/11/30/how-to-use-umbraco-library-getmedia-in-xslt/ but for a simple example see below

    <img src="{umbraco.library:GetMedia(./data[@alias='hostelimage'], false())/data[@alias='umbracoFile']}" />

    Dan

  • Roger Hughes 55 posts 88 karma points
    Feb 23, 2010 @ 15:49
    Roger Hughes
    0

    Thanks Dan,

    The link doesnt work for me but the code works perfect.

    Thanks

    Rog

  • dandrayne 1138 posts 2262 karma points
    Feb 23, 2010 @ 16:02
    dandrayne
    0

    Cool, but be aware that the code above will throw an error if for any reason the image is not picked.  Best bet is something like

    <xsl:if test="string(./data[@alias='hostelimage']) != ''">
    <img
    src="{umbraco.library:GetMedia(./data[@alias='hostelimage'], false())/data[@alias='umbracoFile']}" />
    </xsl:if>

    Dan

     

    p.s. If I had a penny for every time I wrote

    <xsl:if test="string(./data[@alias='PROPERTY']) != ''">

    I'd be on an island sipping pina coladas by now ^^

  • 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