2 navigation areas with CSS 'selected' class options for root/sub-page etc? Options
mkjones
Posted: Thursday, January 03, 2008 4:32:33 PM
Rank: Enthusiast

Joined: 5/14/2007
Posts: 30
:innocent:

Ohh kay.

It seems when I use 2 navigation areas (root at the top, sub-pages on the left) I loose the CSS 'selected' class from the LI tag on my main root links when drilling down?

I have looked around and noticed there is a way to code this out there but it has yet eluded me? :hmm:

Can anyone help?
drobar
Posted: Thursday, January 03, 2008 9:03:44 PM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,698
Location: KY, USA
Please show us the xslt you're using for the two navigation macros so we can help you.

My guess (and it is only a guess since I haven't seen your xslt) is that the main navigation macro needs to include a check for the ancestors to set the proper item "selected" when you are on a sub-page.

I use something like this code to highlight the main nav sections...

Code:

<ul id="mainNav">

    <xsl:for-each select="//node [@level = 1 and @nodeTypeAlias = 'Section' and string(data [@alias='umbracoNaviHide']) != '1']">
    <li>
        <xsl:attribute name="id">mainNav-<xsl:value-of select="@id"/></xsl:attribute>
        <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
            <xsl:attribute name="class">currentsection</xsl:attribute>
        </xsl:if>
        <a>
            <xsl:attribute name="href">
                <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
            </xsl:attribute>
            <xsl:value-of select="@nodeName"/>
        </a>
    </li>
    </xsl:for-each>


</ul>



cheers,
doug.

MVP 2007-2009 - Official Umbraco Trainer for North America - Percipient Studios
mkjones
Posted: Friday, January 04, 2008 11:37:02 AM
Rank: Enthusiast

Joined: 5/14/2007
Posts: 30
SORRY :)

My mail navigation:

Code:
<?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"
    exclude-result-prefixes="msxml umbraco.library">


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

<xsl:param name="currentPage"/>

<xsl:template match="/">

<!-- start writing XSLT -->

<ul id="Navi">
<xsl:for-each select="$currentPage/ancestor::root/node [string(./data [@alias='umbracoNaviHide']) != '1']">
    <li>
        <xsl:if test="$currentPage/@id=current()/@id">
            <xsl:attribute name="class">current</xsl:attribute>
        </xsl:if>

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

</ul>


</xsl:template>

</xsl:stylesheet>


AND My Sub-Navigation which feeds off the current page and displays the sub-pages:

[code=xslt]<?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"
exclude-result-prefixes="msxml umbraco.library">


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

<xsl:param name="currentPage"/>

<!-- Input the documenttype you want here -->
<xsl:variable name="level" select="1"/>

<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:value-of select="@nodeName"/>
</a>
</li>
</xsl:for-each>
</ul>

</xsl:template>

</xsl:stylesheet>[code]


As you can see I don't even have an IF statement in my sub-nav as I just couldn't get it working.

I can get the main navigation to change the class when you are on the root page but it loses it after this.
mkjones
Posted: Friday, January 04, 2008 11:40:07 AM
Rank: Enthusiast

Joined: 5/14/2007
Posts: 30
Sorry, messed up. My Sub-Nav:

Code:
<?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"
    exclude-result-prefixes="msxml umbraco.library">


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

<xsl:param name="currentPage"/>

<!-- Input the documenttype you want here -->
<xsl:variable name="level" select="1"/>

<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:value-of select="@nodeName"/>
        </a>
    </li>
</xsl:for-each>
</ul>

</xsl:template>

</xsl:stylesheet>


Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.