Copied to clipboard

Flag this post as spam?

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


  • Andrew Denham 8 posts 28 karma points
    May 05, 2011 @ 17:27
    Andrew Denham
    0

    Render Image from Media Picker

    HI there,

    I am completely stuck on how to render an image from the media uploader, using Embedded Content, to show on the actual page!? All that is showing is the media ID. My XSL is below.

    I have searched and see that this may be something to do with not having created a macro but really I am completely lost in using this with Embedded Content.

    "icon" is the image and everything else works and shows fine?

    Any help and solutions would really be appreciated.

    Thank you

    Andy

    <xsl:for-each select="$currentPage/staffMembers/data/item">
    <ul
    >
    <li><xsl:value-of select="icon"/></li>
    <li><xsl:value-of select="name"/></li>
    <li><xsl:value-of select="role"/></li>
    <li><xsl:value-of select="email"/></li>
    </ul>
    </xsl:for-each>

  • Brendan Rice 538 posts 1099 karma points
    May 05, 2011 @ 17:57
    Brendan Rice
    0

    What helps me a lot is if I do the following in the xslt:

    <textarea><xsl:copy-of select="." /></textarea>

    or

    <textarea><xsl:copy-of select="icon" /></textarea>

    or

    <textarea><xsl:copy-of select="icon" /></textarea>

     

    This allows you to see the exact structure of the xml you are dealing with in a textbox.

    Hope this helps.

  • Andrew Denham 8 posts 28 karma points
    May 05, 2011 @ 18:17
    Andrew Denham
    0

    Hi Brendan,

    Thanks for this tip! Will be useful in future too. Now where my image should be is

    <icon propertyid="1">1077</icon>

    Not sure yet what to do with this info?

    Any solutions would be welcome?

    Thanks

    Andy

  • Dirk Seefeld 126 posts 665 karma points
    May 05, 2011 @ 19:44
    Dirk Seefeld
    0

    Hi Brendan,

    here is a xslt snippet to build an img tag from the media id:

    <img>
      <xsl:attribute name="src">
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/icon, 'false')/umbracoFile"/>
      </xsl:attribute>
       <xsl:attribute name="alt">
         <xsl:value-of select="umbraco.library:GetMedia($currentPage/icon, 'false')/@nodeName"/>
      </xsl:attribute>
    </img>

    Dirk

  • Sam 184 posts 209 karma points
    May 05, 2011 @ 20:33
    Sam
    0

    Hi Andy,

    You could also try this:

    <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/ALIAS_OF_YOUR_MEDIA_PICKER_IMG_HERE, false())" />
    <img id="headerImage" alt="{$media/@nodeName}" src="{$media/umbracoFile}" width="{$media/umbracoWidth}" />

    Sam.

     

  • Brendan Rice 538 posts 1099 karma points
    May 05, 2011 @ 22:16
    Brendan Rice
    0

    As Dirk and Sam pointed out you only get the ID of the media item, you then have to do a seperate lookup to get that media items xml data.

  • Andrew Denham 8 posts 28 karma points
    May 06, 2011 @ 09:39
    Andrew Denham
    0

    Hi guys,

    Thank you so much for your help so far. Unfortunately it seem I understand this less than I thought as I don't know where to place this image tag? I'm assuming I'm right in trying to put it in the xsl file but I don't know where? I have ttroed both Dirk and Sam's and neither seem to have worked? When I have placed them in places where I can save without errors it just stops rendering anything from this file (Firebug says "Error parsing XSLT file: \xslt\StaffMembers.xslt").

    Seriously, thank you all for your help and advice so far. Anymore tips and advice to get this to work would be great? Like possibly where to place this img tag or other ideas?

    Thank you

    Andy         

  • Dirk Seefeld 126 posts 665 karma points
    May 06, 2011 @ 09:46
    Dirk Seefeld
    0

    Hi Andrew,

    one possible place, based on your fragment, could be here (replacing the icon id value):

    <xsl:for-each select="$currentPage/staffMembers/data/item">
    <ul
    >
    <li>
    <img>
      <xsl:attribute name="src">
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/icon, 'false')/umbracoFile"/>
      </xsl:attribute>
       <xsl:attribute name="alt">
         <xsl:value-of select="umbraco.library:GetMedia($currentPage/icon, 'false')/@nodeName"/>
      </xsl:attribute>
    </img></li>
    <li><xsl:value-of select="name"/></li>
    <li><xsl:value-of select="role"/></li>
    <li><xsl:value-of select="email"/></li>
    </ul>
    </xsl:for-each>

    Dirk

  • Andrew Denham 8 posts 28 karma points
    May 06, 2011 @ 10:17
    Andrew Denham
    0

    Thanks for your quick response Dirk!

    Still producing the same error "Error parsing XSLT file: \xslt\StaffMembers.xslt"!? Is it something to do with using the Embedded Content package?

    I didn't think it would be this hard to produce an image from the media file!

    Thanks again

    Andy

  • Sam 184 posts 209 karma points
    May 06, 2011 @ 10:58
    Sam
    1

    Hi Andy,

    You said earlier that 'icon' is the image. Is that the alias of the media picker or the name of your actual image ie icon.png? The error could be caused by not choosing an image in the content section before running the macro.

    In the doctype that is used for whatever page you're on, there should be a media picker with an alias of 'icon'. Make sure that has an image associated with it.

    Could you post your entire xslt file here so we can see possible other causes of error?

    Also, what is the structure of your site? Maybe $currentPage is wrong. Could try:

    <xsl:variable name="media" select="umbraco.library:GetMedia(ALIAS_OF_YOUR_MEDIA_PICKER_IMG_HERE, false())" />
    <img id="headerImage" alt="{$media/@nodeName}" src="{$media/umbracoFile}" width="{$media/umbracoWidth}" />

    Basically, where are the pages located that use the media picker in relation to the actual page on your site that the image is displayed?

    If that makes any sense? :)

    Sam.

  • Andrew Denham 8 posts 28 karma points
    May 06, 2011 @ 11:31
    Andrew Denham
    0

    Thanks Sam!

    It was simply that $currentPage was wrong! Fell a bit stupid when it is something like that! Not used to Umbraco enough yet to have seen it!

    Thank you again and to Brendan and Sam too!

    Andy

  • Sam 184 posts 209 karma points
    May 06, 2011 @ 11:34
    Sam
    0

    Hi Andy,

    Glad you got it sorted :)

    Sam.

Please Sign in or register to post replies

Write your reply to:

Draft