Copied to clipboard

Flag this post as spam?

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


  • Chris Knowles 141 posts 222 karma points
    Nov 03, 2011 @ 15:40
    Chris Knowles
    0

    GetItem not returning anything

    Hi,

    My site has 5 related product content pickers and i can see from the XML that they all have some data in it. I am trying to get the title of the related product so i can link to it. I can get the link to work using the NiceUrl library but when i try and get the title of the item it returns nothing?

    <xsl:value-of select="umbraco.library:GetItem($currentPage/relatedProduct1, 'title')"/>

    Can someone point me in the right direction or see if i've been a bit dumb?

    Thanks

    Chris

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Nov 03, 2011 @ 15:58
    Tom Fulton
    0

    Hi Chris,

    I've never really used GetItem, but it looks like that should work.  Does the target product have a field called "title" or are you actually trying to get the @nodeName ?  Per this wiki it seems you cannot get the nodeName and other "attributes", only field data.

    -Tom

  • Chris Knowles 141 posts 222 karma points
    Nov 03, 2011 @ 16:00
    Chris Knowles
    0

    Hi Tom,

    title is an field i have put as i saw you couldn't get to the @nodeName, i have read that wiki too but thought i was doing something wrong. The picked node does have a title field with something in it but i can inly assume that the GetItem function doesn't work? 

    Do you know a different way i could do it?

    Thanks

    Chris

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Nov 03, 2011 @ 16:03
    Tom Fulton
    0

    Try this:

    <xsl:if test="$currentPage/relatedProduct1 &gt; 0"> <!-- You might need this line to avoid errors when saving -->
    <xsl:variable name="targetPage" select="umbraco.library:GetXmlNodeById($currentPage/relatedProduct1)"/>
    <xsl:if test="not($targetPage/error)">
    Title:  <xsl:value-of select="$targetPage/title"/>
    </xsl:if>
    </xsl:if>

    -Tom

  • Chris Knowles 141 posts 222 karma points
    Nov 03, 2011 @ 17:06
    Chris Knowles
    0

    Thanks Tom,

    here's my final solution:

                <xsl:if test="$currentPage/relatedProduct3 != '' and $currentPage/relatedProduct3 != $currentPage/@id">
                    <xsl:variable name="targetPage3" select="umbraco.library:GetXmlNodeById($currentPage/relatedProduct3)"/>
                    <xsl:if test="not($targetPage3/error)">
                        <a href="{umbraco.library:NiceUrl($targetPage3/@id)}">
                            <xsl:choose>
                                <xsl:when test="$targetPage3/title != ''">
                                    <xsl:value-of select="$targetPage3/title" />
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="$targetPage3/@nodeName" />
                                </xsl:otherwise>
                            </xsl:choose>
                        </a>
                        <br />
                        <hr />
                    </xsl:if>
                </xsl:if>
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Nov 03, 2011 @ 17:26
    Tom Fulton
    0

    Cool, glad it worked...not sure what's up with GetItem.

    Also are you duplicating that code block for each picker?  You could make one template to handle it all :)

    -Tom

Please Sign in or register to post replies

Write your reply to:

Draft