Copied to clipboard

Flag this post as spam?

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


  • Inmedia 124 posts 176 karma points
    Jul 22, 2009 @ 14:33
    Inmedia
    0

    Sub navigation issue

    Hi Umbracians

    I have a little problem with my subnavigation, that should be fairly easy to fix, but I am not that good at XSLT yet, so I simply don't know how to fix this.

    Here is the problem:

    I have created an XSLT for my subnavigation that looks like this

    <xsl:output method="xml" omit-xml-declaration="yes" />
    <xsl:param name="currentPage"/>
    <xsl:variable name="level" select="2"/>
    <xsl:template match="/">

    <!-- The fun starts here -->

    <ul>
    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node[string(data [@alias='umbracoNaviHide']) != '1']">
     <li> 
      <a href="{umbraco.library:NiceUrl(@id)}">
      <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
      <!-- we're under the item - you can do your own styling here -->
      <xsl:attribute name="style">font-weight: bold;</xsl:attribute>
      </xsl:if>
      <xsl:value-of select="@nodeName"/>
      </a>
     </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

    A standard subnavigation as you see. But I want it not only to list the subpages from the page selected in the 1st level (my main navigation)... I want it to show the page 1 level before all this subpages.

    I don't know how to explain it better, but here is the website I am working on.

    www.priusejendomsinvest.dk  (it's in danish)

    And if you click "Om Prius Ejendomsinvest", you get the subpages for that subject... But I also want it to list the "Om Prius Ejendomsinvest" page.

    I would think its pretty simple if you just know how... But I don't :)
    So I was hopping some of you guys could help me out here??

     

     

  • dandrayne 1138 posts 2262 karma points
    Jul 22, 2009 @ 14:42
    dandrayne
    0

    change

    <xsl:variable name="level" select="2"/>

    to

    <xsl:variable name="level" select="1"/>

    for a start, then see what you get

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 22, 2009 @ 14:46
    Dirk De Grave
    1

    Don't you just need to include a <li> element for the current page before the for-each statement?

    <ul>
      <li><a href="{umbraco.library:NiceUrl($currentPage/@id)}"> <xsl:value-of select="$currentPage/@nodeName"/></a></li>
      ...
    </ul>

    Hope this helps.

     

    Regards,

    /Dirk

     

  • dandrayne 1138 posts 2262 karma points
    Jul 22, 2009 @ 14:52
    dandrayne
    0

    Ah, yes - +1 for reading the question correctly :-D

  • Vladimir Dobrov 45 posts 167 karma points
    Jul 22, 2009 @ 14:57
    Vladimir Dobrov
    0

    Think you should do it in the following way

    <xsl:output method="xml" omit-xml-declaration="yes" />
    <xsl:param name="currentPage"/>
    <xsl:variable name="level" select="2"/>
    <xsl:template match="/">

    <!-- The fun starts here -->

    <ul>

    <!-- the new code that displays link to level 2 page -->

    <xsl:variable name="level2page" select="$currentPage/ancestor-or-self::node [@level=$level]"/>

     <li>
      <a href="{umbraco.library:NiceUrl($level2page/@id)}">
      <xsl:if test="$currentPage/ancestor-or-self::node/@id = $level2page/@id">
      <xsl:attribute name="style">font-weight: bold;</xsl:attribute>
      </xsl:if>
      <xsl:value-of select="$level2page/@nodeName"/>
      </a>
     </li>

    <!-- the new code ends-->



    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node[string(data [@alias='umbracoNaviHide']) != '1']">
     <li>
      <a href="{umbraco.library:NiceUrl(@id)}">
      <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
      <!-- we're under the item - you can do your own styling here -->
      <xsl:attribute name="style">font-weight: bold;</xsl:attribute>
      </xsl:if>
      <xsl:value-of select="@nodeName"/>
      </a>
     </li>
    </xsl:for-each>
    </ul>

    </xsl:template>

     

    Hope this will help.

    BTW you have redudant add of attribute style="font-weight:bold" becouse of your css defines it as bold always.

  • Vladimir Dobrov 45 posts 167 karma points
    Jul 22, 2009 @ 15:00
    Vladimir Dobrov
    0

    2 Dirk

    I think the task is not to display link to the current page but the link to the parent page of the pages listed in subnavigation.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 22, 2009 @ 15:15
    Dirk De Grave
    0

    You're right Vladimir, must have misunderstood, indeed, needs to have link to parent page only, no matter what child node page he's on...

    On the other hand (talking to inmedia again), why repeat that page if that one is already marked as selected section  in top navigation?

     

    Cheers,

    /Dirk

  • Vladimir Dobrov 45 posts 167 karma points
    Jul 22, 2009 @ 15:36
    Vladimir Dobrov
    0

    Agree with you Dirk about non-logical requirements. But sometimes customer wants wired things =)

    I think this link to the parent page at least should have a different look.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 22, 2009 @ 15:41
    Dirk De Grave
    0

    up to inmedia to educate the customer then :p

  • Inmedia 124 posts 176 karma points
    Jul 22, 2009 @ 16:34
    Inmedia
    0

    Hi Vladimir

    I think your answer might be the solution... But... (And here comes a really stupid question, I guess)... Do I need to replace the "$level2page" with something? Cause I get an error trying to save it as you posted it.

    And yes, I agree that it is a non-logical requirement, but the customer is (almost) always right :)

     

  • Inmedia 124 posts 176 karma points
    Jul 23, 2009 @ 12:39
    Inmedia
    0

    No one???.....

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 23, 2009 @ 13:05
    Dirk De Grave
    0

    Error is probably due to fact that $level2page doesn't have a value until runtime, but NiceUrl expects a int parameter... Either surround with xsl:if statement or tick the 'Ignore errors' checkbox.

    Does it render ok at the front-end?

     

    Cheers,

    /Dirk

     

  • Inmedia 124 posts 176 karma points
    Jul 23, 2009 @ 13:25
    Inmedia
    0

    Hi Dirk

    I ticked the "ignore error" and it works and renders perfect... Thank you for helping out a rookie :)

     

     

  • Vladimir Dobrov 45 posts 167 karma points
    Jul 24, 2009 @ 10:43
    Vladimir Dobrov
    0

    What kind of error do you have?

     

  • Vladimir Dobrov 45 posts 167 karma points
    Jul 24, 2009 @ 10:44
    Vladimir Dobrov
    0

    Oops, error is resolved. Don't forget to mark a post as a solution ;)

Please Sign in or register to post replies

Write your reply to:

Draft