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 06, 2011 @ 18:10
    Andrew Denham
    0

    NiceUrl linking from content picker

    It's Andy again!

    I have my macro working fine on my home page now but when I use it on a child page the NiceUrl code that I used in it produces a parse error on the child page!? I know it is this bit as if I remove it the content shows as expected!

    The 'title' is the page selected with the content picker and 'pageTitle' is the name of the page typed in a TextString!

    I'm not sure what to put so that it works on both the home page and a child page?

    Please could someone help me with a suggestion? Or a better way to do it?

    Thank you very much

    Andy

    <xsl:template match="/">

    <xsl:for-each select="$currentPage/navIcon/data/item">

    <div class="navicon">
    <xsl:if test="position() mod 4 = 0">
    <xsl:attribute name="class">navicon4</xsl:attribute>
    </xsl:if>
    <xsl:variable name="media" select="umbraco.library:GetMedia(icon, false())" />
    <a href="{umbraco.library:NiceUrl(title)}">
    <img alt="{$media/@nodeName}" src="{$media/umbracoFile}" width="{$media/umbracoWidth}" />
    </a>
    <a href="{umbraco.library:NiceUrl(title)}">
    <xsl:value-of select="pageTitle"/>
    </a>
    <p><xsl:value-of select="description" /></p>
    </div>

    </xsl:for-each>

    <xsl:template>
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 07, 2011 @ 00:06
    Jan Skovgaard
    0

    Hi Andy

    Does the title field also exist on your child page? If it's empty that's probably why you get the error...what happens if you try to amend your for-each from this

      <xsl:for-each select="$currentPage/navIcon/data/item">

    to

      <xsl:for-each select="$currentPage/ancestor-or-self::*/navIcon/data/item">

    Does this work?

    /Jan

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    May 07, 2011 @ 00:39
    Chriztian Steinmeier
    0

    Hi Andy,

    If NiceUrl() is the cause, there must be an <item> element with an empty or non-existent <title>, because that code only executes on <item> elements.

    Try the following to debug:

    <xsl:template match="/">
        <xsl:for-each select="$currentPage/navIcon/data/item">
            <xsl:variable name="link">
                <xsl:if test="normalize-space(title)">
                    <xsl:value-of select="umbraco.library:NiceUrl(link)" />
                </xsl:if>
            </xsl:variable>
            <xsl:variable name="media" select="umbraco.library:GetMedia(icon, false())" />
    
            <div class="navicon">
                <xsl:if test="position() mod 4 = 0">
                    <xsl:attribute name="class">navicon4</xsl:attribute>
                </xsl:if>
                <a href="{$link}">
                    <img alt="{$media/@nodeName}" src="{$media/umbracoFile}" width="{$media/umbracoWidth}" />
                </a>
                <a href="{$link}">
                    <xsl:value-of select="pageTitle"/>
                    <xsl:if test="not($link)"> (has faulty title!)</xsl:if>
                </a>
                <p><xsl:value-of select="description" /></p>
            </div>
        </xsl:for-each>
    <xsl:template>

     

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft