Apply style to Home (related link) node in navigation
I have a web site (from a starter kit) with with following navigation structure in the Content section:
--------------------------------------------- CONTENT -Home -Home (this is a related link back to "\" which redirects to top Home node) -About -Page 3 -etc. ---------------------------------------------
I have a .Selected CSS style which is correctly applied to all nav and sub nav items EXCEPT Home. I imagine that it is b/c the "Home" in my menu is a related link and is only there to point back to web page root.
I confirmed that my CSS style "selected" is not set on the Home node. I believe I need to modify the following XSLT but havent had any success figuring out how to get it working. Any suggestions would be appreciated:
It's a little cryptic what you're doing with the $linkNone variable, but I think the reason your "Home" node doesn't get the .selected class is because you specifically ask if the "current page or one of its ancestors ABOVE level 1" etc. - Home is probably at level 1, right?
Change the "greater than" (>) to "greater than or equal to" (>=) and see if that's not what you want...
I started this web site with a stater package (Kioak Standard Site) so I cant explain the thinking behind the linkNone variable either. I've learn alot about Umbraco, but the XSLTs are still pretty confusing to me at this point.
Here is the entire XSLT if that will help. I left out the suggestion you made so you could see the original. I still feel like the HOME being a related link to my topmost Node (Homepage) is the cause for the confusion but not sure how to handle it. Thanks for trying...
Apply style to Home (related link) node in navigation
I have a web site (from a starter kit) with with following navigation structure in the Content section:
---------------------------------------------
CONTENT
-Home
-Home (this is a related link back to "\" which redirects to top Home node)
-About
-Page 3
-etc.
---------------------------------------------
I have a .Selected CSS style which is correctly applied to all nav and sub nav items EXCEPT Home. I imagine that it is b/c the "Home" in my menu is a related link and is only there to point back to web page root.
I confirmed that my CSS style "selected" is not set on the Home node. I believe I need to modify the following XSLT but havent had any success figuring out how to get it working. Any suggestions would be appreciated:
<xsl:variable name="linkNone" select="$rootPage//*[@isDoc][@id = string(current()/.)]"/>
<xsl:if test="string-length($linkNone/@id)> 0">
<li>
<xsl:attribute name="class">
<xsl:if test="$currentPage/ancestor-or-self::*[@level > 1]/@id = $linkNone/@id">
<xsl:text>selected</xsl:text>
</xsl:if>
<xsl:if test="position() = last()">
<xsl:text>last</xsl:text>
</xsl:if>
</xsl:attribute>
..etc...
Hi MHH311,
It's a little cryptic what you're doing with the $linkNone variable, but I think the reason your "Home" node doesn't get the .selected class is because you specifically ask if the "current page or one of its ancestors ABOVE level 1" etc. - Home is probably at level 1, right?
Change the "greater than" (>) to "greater than or equal to" (>=) and see if that's not what you want...
/Chriztian
Thanks for the suggestion Chriztian. I tried the suggestion you made and it did not work. I assume this is what you meant to try?
<xsl:if test="$currentPage/ancestor-or-self::*[@level >= 1]/@id = $linkNone/@id">
I started this web site with a stater package (Kioak Standard Site) so I cant explain the thinking behind the linkNone variable either. I've learn alot about Umbraco, but the XSLTs are still pretty confusing to me at this point.
Here is the entire XSLT if that will help. I left out the suggestion you made so you could see the original. I still feel like the HOME being a related link to my topmost Node (Homepage) is the cause for the confusion but not sure how to handle it. Thanks for trying...
********************
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
]>
<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"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="rootPage" select="$currentPage/ancestor-or-self::root"/>
<xsl:variable name="propertyAlias" select="/macro/PropertyAlias"/>
<xsl:template match="/">
<xsl:variable name="homepage" select="$currentPage/ancestor-or-self::Homepage"/>
<xsl:variable name="nodeIds" select="umbraco.library:Split($homepage/*[name()=$propertyAlias],',')" />
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
<ul class="navigation fc">
<!-- <ul class="navbar UL"> -->
<xsl:for-each select="$nodeIds/value">
<xsl:variable name="linkNone" select="$rootPage//*[@isDoc][@id = string(current()/.)]"/>
<xsl:if test="string-length($linkNone/@id)> 0">
<li>
<xsl:attribute name="class">
<xsl:if test="$currentPage/ancestor-or-self::*[@level > 1]/@id = $linkNone/@id">
<xsl:text>selected</xsl:text>
</xsl:if>
<xsl:if test="position() = last()">
<xsl:text>last</xsl:text>
</xsl:if>
</xsl:attribute>
<xsl:choose>
<xsl:when test="string-length($linkNone/umbracoUrlAlias) > 0">
<a href="{$linkNone/umbracoUrlAlias}">
<xsl:value-of select="$linkNone/@nodeName"/>
</a>
</xsl:when>
<xsl:otherwise>
<a href="{umbraco.library:NiceUrl($linkNone/@id)}">
<xsl:value-of select="$linkNone/@nodeName"/>
</a>
</xsl:otherwise>
</xsl:choose>
</li>
</xsl:if>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
is working on a reply...