Copied to clipboard

Flag this post as spam?

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


  • Daniel Nøhr 14 posts 35 karma points
    Sep 09, 2009 @ 14:11
    Daniel Nøhr
    0

    Active navigation node - Any code for that?

    Hello all :-)

    I was wondering if there is any code for checking if the current node in the navigation is active? By active i mean if the current node if the page I'm currently watching..

    I have tried search for any "active" questions, but couldn't find anything :)

  • Tim 225 posts 690 karma points
    Sep 09, 2009 @ 14:17
    Tim
    0

    Hi,

    In an umbraco macro the $currentPage variable contains the node that the user is currently on.

    If you want to learn more about navigation or need a simple leg up to get your nav started take a look at my http://our.umbraco.org/projects/cogworks---flexible-navigation">navigation package

    Tim

  • montana 42 posts 63 karma points
    Oct 14, 2010 @ 23:26
    montana
    0

    @Tim

    "...nav started take a look at my navigation package"

    ^ broken link

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 15, 2010 @ 00:27
    Chriztian Steinmeier
    0

    Hi Daniel,

    You can ask that question like this, e.g., if you're inside a for-each on document nodes:

    <!-- Inside xsl:template or xsl:for-each -->
    <xsl:if test="@id = $currentPage/@id">
        <!-- stuff -->
    </xsl:if>

    /Chriztian

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 15, 2010 @ 00:30
    Chriztian Steinmeier
    0

    Gee - old thread :-)

    @montana: Just search for it - it's called "flexible navigation" - but agreed; there ought to be some URL redirection going on for the old URLs to packeages/projects

    /Chriztian

  • montana 42 posts 63 karma points
    Oct 15, 2010 @ 00:54
    montana
    0

    I just started with umbraco and this was a hot topic - was just hitting all the threads trying to dig this up. Ended up writing this:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:tagsLib="urn:tagsLib"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib ">

        <xsl:output method="xml" omit-xml-declaration="yes"/>

        <xsl:param name="currentPage"/>

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

        <xsl:variable name="source" select="umbraco.library:GetXmlNodeByXPath('/root') [string(umbracoNaviHide)!='1']" />

        <!--
           update this variable on how deep your site map should be
        -->

        <xsl:variable name="maxLevelForSitemap" select="10"/>

        <xsl:template match="/">
            <ul class="nav_list">
                <xsl:call-template name="drawNodes">
                    <xsl:with-param name="parent" select="$source"/>
                </xsl:call-template>
            </ul>
        </xsl:template>

        <xsl:template name="drawNodes">
            <xsl:param name="parent"/>
            <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
                <xsl:for-each select="$parent/* [@isDoc and @level &lt;= $maxLevelForSitemap and string(umbracoNaviHide)!='1']">

                    <li onmouseover="$(this).addClass('over');" onmouseout="$(this).removeClass('over');" >
                        <!-- duplicate ^ "over' class here to "open" class from below and you have a fully expandable/collapsable with active state hierarchical menu-->

                        <xsl:if test="contains( concat($currentPage/@path, ','), concat(',', @id, ',') )">
                            <xsl:attribute name="class">open</xsl:attribute>
                        </xsl:if>

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

                        <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">
                            <ul>
                                <xsl:call-template name="drawNodes">
                                    <xsl:with-param name="parent" select="."/>
                                </xsl:call-template>
                            </ul>
                        </xsl:if>
                    </li>
                </xsl:for-each>
            </xsl:if>
        </xsl:template>

    </xsl:stylesheet>

     

Please Sign in or register to post replies

Write your reply to:

Draft