Copied to clipboard

Flag this post as spam?

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


  • Yael Manshary 17 posts 57 karma points
    Mar 03, 2013 @ 11:23
    Yael Manshary
    0

    recursive link and image using urlPicker

    Hi Guys,

    Could not figure this out...

    I have a site with banners in almost each page. The banners are links.

    I am using the urlPicker component for the links.

    I need the image and the links to be recursive.

    So far I've mannaged to make the image recursive and it works fine but I could do this to the link.

    This is my current code:

    <xsl:template match="/">
    <xsl:for-each select="$currentPage [@isDoc and string(umbracoNaviHide) != '1']">
    <div class="banner-wrap">
            <a class="home_banner top_banner" href="{bannerLink/url-picker/url}">
                    <xsl:if test="bannerLink/url-picker/new-window[. = 'True']">
                            <xsl:attribute name="target">_blank</xsl:attribute>
                    </xsl:if>
                    <xsl:apply-templates select="ancestor-or-self::*[normalize-space(banner)][1]/banner" />
            </a>
    </div>
    </xsl:for-each>
    </xsl:template>
    <xsl:template match="banner">
      <img src="{.}" alt="{../bannerAlt}" title="{../bannerAlt}" />
    </xsl:template>
    </xsl:stylesheet>

     

    Would  appreciate any help.

    Thank you!

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 04, 2013 @ 08:22
    Chriztian Steinmeier
    100

    Hi Yael,

    You can do pretty much the same as you do with the banner - the trick is to create a template to handle the url-picker property and then apply the template to the one that has a non-empty value in the <url> "subfield":

    <xsl:template match="/">
        <xsl:for-each select="$currentPage [@isDoc and string(umbracoNaviHide) != '1']">
            <div class="banner-wrap">
                <a class="home_banner top_banner">
                    <!-- Handle the link recursively -->
                    <xsl:apply-templates select="ancestor-or-self::*[normalize-space(bannerLink/url-picker/url)][1]/bannerLink/url-picker" />
                    <xsl:apply-templates select="ancestor-or-self::*[normalize-space(banner)][1]/banner" />
                </a>
            </div>
        </xsl:for-each>
    </xsl:template>
    
    <xsl:template match="banner">
        <img src="{.}" alt="{../bannerAlt}" title="{../bannerAlt}" />
    </xsl:template>
    
    <xsl:template match="url-picker">
        <xsl:attribute name="href">
            <xsl:value-of select="url" />
        </xsl:attribute>
        <xsl:if test="new-window = 'True'">
            <xsl:attribute name="target">_blank</xsl:attribute>
        </xsl:if>
    </xsl:template>
    
    - and I moved the handling of the target attribute into that template as well, since it's tied to the link...

    /Chriztian

  • Yael Manshary 17 posts 57 karma points
    Mar 04, 2013 @ 10:04
    Yael Manshary
    0

    Hi Chriztian,

    It works!

    Also, your solution is very clear and I will surely use it for other things.

    Thank you very much for your help,

    Yael

Please Sign in or register to post replies

Write your reply to:

Draft