Copied to clipboard

Flag this post as spam?

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


  • Bostjan 4 posts 24 karma points
    Jul 04, 2011 @ 10:50
    Bostjan
    0

    Getting image of a content chosen in the content picker

    Hi,

    I'm trying to display an image stored in a field of a specific content node that is chosen at the time of placing a macro with the content picker.

    What I have thus far is basically this, which works for the content field, but not for the picture.

    <code>

    <xsl:variable name="source" select="/macro/source"/>   
    <xsl:variable name="picID" select="umbraco.library:GetXmlNodeById($source)/picture"/>


        
    <xsl:template match="/">

    <!-- start writing XSLT -->
      <div id="prodSpotlight">    
       
        <xsl:if test="string($picID) != ''">
        <!-- Show image -->
        <img>
          <xsl:attribute name="src">
            <xsl:value-of select="umbraco.library:GetMedia($picID, 'false')/data [@alias = 'umbracoFile']"/>
          </xsl:attribute>
        </img>
        </xsl:if>
      </div>
      <div id="prodFeatures">
        <xsl:value-of select="umbraco.library:GetXmlNodeById($source)/content" disable-output-escaping="yes"/>
      </div>

    </code>

     

    Can anyone point me in the right direction?


    Thanks

     

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 04, 2011 @ 11:18
    Dirk De Grave
    0

    Bostjan,

    Bit confused, I guess you mean you're selecting the image through the media picker instead of content picker, right? I don't think the picID variable is set correctly as you're already passing the id of the media item?

    So, I think the 'source' variable already holds the id of the media item.

    Secondly, depending on whether you use the old or new xml schema, you'd need to change the way you're getting the path of the media item... (you're using the old schema version method)

    If you're using the new xml schema, you'd need to write

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

     

    Hope this helps.

    Regards,

    /Dirk

  • Bostjan 4 posts 24 karma points
    Jul 04, 2011 @ 11:32
    Bostjan
    0

    Actually no. I'm using content picker to select the node which I want to display. This node has a document type that stores 4 fields (title, url, content and picture).

    Source variable is the ID of that node. I can extract the content, title and url fields just fine with the

     <xsl:value-of select="umbraco.library:GetXmlNodeById($source)/content" disable-output-escaping="yes"/>

    but I have no idea how to extract the picture field. This is what I would need help with.

     

    Thank you.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 04, 2011 @ 11:41
    Dirk De Grave
    0

    Ah ok, misunderstood the question, code makes more sense now...

    Anyway, you're still using both new and old syntax... the variable picID is assigned using the new syntax whereas you're selecting the image path using the old syntax... so, can you tell us whether you're using the new or old xml syntax? (can be found in umbracoSettings.config)

    <!-- to enable new content schema, this needs to be false -->
    <UseLegacyXmlSchema>false</UseLegacyXmlSchema>

    If it's set to true, then you need to change the way you fetch the variable picID

    <xsl:variable name="picID" select="umbraco.library:GetXmlNodeById($source)/data [@alias = 'source']"/>

    if it's set to false, than you need to use the code snippet I provided for getting the image path

     

    Hope this helps.

    Regards,

    /Dirk

     

     

     

     

  • Bostjan 4 posts 24 karma points
    Jul 04, 2011 @ 12:07
    Bostjan
    0

    First of all, thank you for your troubles.

    I'm using the new content schema and adjusted my code to reflect that. The code looks now like this:

    <xsl:variable name="source" select="/macro/source"/>  
    <xsl:variable name="picID" select="umbraco.library:GetXmlNodeById($source)/picture"/>
    <xsl:template match="/">

    <!-- start writing XSLT -->
      <div id="prodSpotlight">   
      
        <xsl:if test="string($picID) != ''">
        <!-- Show image -->
        <img>
          <xsl:attribute name="src">
            <xsl:value-of select="umbraco.library:GetMedia($picID, 'false')/umbracoFile"/>
          </xsl:attribute>
        </img>
        </xsl:if>
      </div>
      <div id="prodFeatures">
        <xsl:value-of select="umbraco.library:GetXmlNodeById($source)/content" disable-output-escaping="yes"/>
      </div>
    </xsl:template>

    It's still not returning the picture though. I get an odd result such as:

    <div id="prodSpotlight"><div id="prodFeatures">Content text here</div></div>

    So basically it's putting one div into the other and not next to each other as it should. The picture is also not being shown.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 04, 2011 @ 12:20
    Dirk De Grave
    0

    Can you add a small code snippet to find out what's being returned by GetMedia() call, it may be missing an extra /Image tag (Always forget what's being returned...)

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

    Put it somewhere on top

    Also, better use false() instead of 'false'

     

    Cheers,

    /Dirk

  • Bostjan 4 posts 24 karma points
    Jul 04, 2011 @ 12:44
    Bostjan
    0

    Well I finally managed. It turns out I don't need to use the getMedia function.
    The below code works:

    <div id="prodSpotlight">   
        <xsl:if test="string(umbraco.library:GetXmlNodeById($source)/picture) != ''">
        <!-- Show image -->
        <img>
          <xsl:attribute name="src">
            <xsl:value-of select="umbraco.library:GetXmlNodeById($source)/picture"/>
          </xsl:attribute>
        </img>
        </xsl:if>
      </div>
      <div id="prodFeatures">
        <xsl:value-of select="umbraco.library:GetXmlNodeById($source)/content" disable-output-escaping="yes"/>
      </div>


    The picture field already returns the url to the picture, not the media ID as I first thought. Thanks for all the help.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 04, 2011 @ 12:50
    Dirk De Grave
    0

    Ok, so you've put a upload field for the image? And indeed, in that case, the image path is saved as part of the published xml. If it were a media picker, than you'd have to use the code provided before.

    Glad you got it working!

    Cheers,

    /Dirk

Please Sign in or register to post replies

Write your reply to:

Draft