Copied to clipboard

Flag this post as spam?

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


  • Dwayne A 97 posts 117 karma points
    Mar 07, 2011 @ 09:09
    Dwayne A
    0

    GetMedia after page id

    Hi,

    Am working on a navigational menu requiring both text links as well as images associated with eah page. The text links work fine, but I am stumped after trying to assosiate the images with the page link.

    The navi should work like this: http://www.koriaarhus.dk/

    My code:

    <xsl:param name="currentPage"/>

        <xsl:template match="/">
          <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::* [@level=1]" />     
            <xsl:variable name="mainMenuItems" select="$siteRoot /*[@isDoc and string(umbracoNaviHide) != '1']" />
              <xsl:apply-templates select="$mainMenuItems" />
        </xsl:template>

        <xsl:template name="ShowMenuItem" match="*">
          <div style="float:left; width:87px; padding-left:12px; padding-top:7px;">
            <p class="link_paragraf">
              <a href="{umbraco.library:NiceUrl(@id)}" class="menulink">
                <xsl:variable name="mediaID" select="$currentPage/linkBillede" />
                <xsl:if test="string($mediaID) != ''">
                  <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/linkBillede, false)" />
                    <xsl:if test="string($media) != ''">
                    <img src="{$media/umbracoFile}" alt="{$media/altText}" class="image" />
                    </xsl:if>
                </xsl:if>
                <xsl:value-of select="@nodeName"/>
              </a>
            </p>
          </div>
        </xsl:template>

     

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 07, 2011 @ 10:02
    Kim Andersen
    1

    Hi Dwayne

    Could you try to change this:

    <xsl:variable name="mediaID" select="$currentPage/linkBillede" />
                <xsl:if test="string($mediaID) != ''">
                  <xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/linkBillede, false)" />
                    <xsl:if test="string($media) != ''">
                    <img src="{$media/umbracoFile}" alt="{$media/altText}" class="image" />
                    </xsl:if>
                </xsl:if>

    To this:

    <xsl:variable name="mediaID" select="./linkBillede" />
                <xsl:if test="string($mediaID) != ''">
                  <xsl:variable name="media" select="umbraco.library:GetMedia($mediaID, false)" />
                    <xsl:if test="string($media) != ''">
                    <img src="{$media/umbracoFile}" alt="{$media/altText}" class="image" />
                    </xsl:if>
                </xsl:if>

    Does that make any difference?

    /Kim A

  • Dwayne A 97 posts 117 karma points
    Mar 07, 2011 @ 10:44
    Dwayne A
    0

    That did the trick! You addressed the top node with ./linkBillede, correct? And then called the variable mediaID instead of currentPage/linkBillede.

  • Kim Andersen 1447 posts 2197 karma points MVP
    Mar 07, 2011 @ 10:48
    Kim Andersen
    0

    Yeah, you where trying to grab the linkBillede from the current page (by using $currentPage), but it should really grab it from the current node that's been iterated through (by using . instead - actually you could probably remove the ./ in front of the linkBillede as well).

    And then I just used the id we found in the $MediaID inside the GetMedia-extension in the $media-variable :)

    /Kim A

  • Dwayne A 97 posts 117 karma points
    Mar 07, 2011 @ 10:58
    Dwayne A
    0

    Exactly. I knew I was not addressing the proper nodes, rather the current page loaded in the browser. I was just uncertain how to address the page node associated with my images. So in order to grab the image from the iterated pages, we create a variable for the property, select the iteration at the top node and pass the property into GetMedia(), it would seem. And you are correct, it works without ./

  • 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.

    Continue discussion

Please Sign in or register to post replies