Test for Current node?
I am trying to change the class on a <li> by adding the code:
<li>
<xsl:attribute name="class">
<xsl:if test="system-folder[descendant::system-page[@current ='true']]">
active
</xsl:if>
</xsl:attribute>
</li>
What am I doing wrong?
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Ryan Griffith on 17 Apr, 2015 05:40 PM
Hi,
You are definitely going in the right direction by checking for a page with
@current
. My guess is thesystem-folder[]
portion of your XPath may be incorrect. When you have a moment, please attach your entire Format so I can take a closer look.Thanks!
2 Posted by voltmer1 on 17 Apr, 2015 08:21 PM
Ryan,
I've got the @current node test to work, but I would really like to be able to do 2 things:
1. only list the current page and it's children
2. template-match on the system-folder containing the current page, so I could have it styled to show which section the user is in.
I hope I explained this clear enough? Thanks for any insight!
3 Posted by Ryan Griffith on 17 Apr, 2015 08:50 PM
Hi,
Just to clarify, by "only list the current page and it's children", do you mean to say "current folder and its children"? If so, you would want to adjust the
<xsl:if>
within the<system-folder>
template to also check to make sure the folder contains a calling page (ie page with@current
) that is not called index.Also, I am seeing a couple of potential issues within the Format:
system-page[name!='']
Please let me know if you have any questions.
Thanks!
4 Posted by voltmer1 on 17 Apr, 2015 08:54 PM
Yes Ryan, I ment to say "current folder and its children". Thanks for your help with this. I'll give it a try and let you know.
Also, just curious, how would I re-order (sort) the order in which the system-folders displayed in a navigation that was to include all of them?
5 Posted by Ryan Griffith on 20 Apr, 2015 11:58 AM
Hi,
Not a problem at all, please let me know if you have any questions about my suggestions.
Is there a specific order in which you would like to sort them (eg alphabetical), or are you looking for a way to manually specify the order?
Thanks!
6 Posted by voltmer1 on 20 Apr, 2015 04:49 PM
I've got it working by using this code, but I would like to move my one page that is not within a system-folder (it is the site index) to the top of the navigation instead of being last.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/system-index-block">
<xsl:if test="count(system-page[name!=''] | system-folder[descendant::system-page] | system-symlink) > 0">
<ul id="left-nav">
<xsl:apply-templates select="system-page[name!=''] | system-folder[descendant::system-page[@current = 'true']] | system-symlink">
</xsl:apply-templates>
</ul>
</xsl:if>
</xsl:template>
<xsl:template match="system-page">
<li>
<xsl:attribute name="class">
<xsl:if test="@current = 'true'">
active
</xsl:if>
</xsl:attribute>
<a>
<xsl:attribute name="href">
<xsl:value-of select="link"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="title != ''">
<xsl:value-of select="title"/>
</xsl:when>
<xsl:when test="display-name != ''">
<xsl:value-of select="display-name"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="name"/>
</xsl:otherwise>
</xsl:choose>
</a>
</li>
</xsl:template>
<xsl:template match="system-folder">
<li>
<xsl:attribute name="class">
<xsl:if test="@current = 'true' and name != 'index'">
active
</xsl:if>
</xsl:attribute>
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat(link,'/index')"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="title != ''">
<xsl:value-of select="title"/>
</xsl:when>
<xsl:when test="display-name != ''">
<xsl:value-of select="display-name"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="name"/>
</xsl:otherwise>
</xsl:choose>
</a>
<xsl:if test="count(system-page[name!='index'] | system-symlink) > 0">
<ul>
<xsl:apply-templates select="system-page[name!='index'] | system-symlink"/>
</ul>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>
7 Posted by Ryan Griffith on 21 Apr, 2015 05:56 PM
Hi,
I think your best bet would be to manually order the pages/folders and make sure you select the Folder Order sorting method for your Index Block. This will give you the most flexibility in terms of ordering your navigation; otherwise, you will be stuck with alphabetical or by creation date, or manually adding the links within the Format itself.
Please let me know if you have any questions.
Thanks!
8 Posted by voltmer1 on 24 Apr, 2015 01:22 PM
Ryan,
I can't get the pages to re-order using the "folder order" of the base folder. It looks correct within the web interface, but not on the website.
9 Posted by Ryan Griffith on 24 Apr, 2015 01:36 PM
Hi,
To clarify, you are seeing the desired order when viewing the page(s) within Cascade, but not on the live website? If so, you will need to re-publish the website in order for the changes to the navigation to be visible on the live website.
Please let me know if you have any questions.
Thanks!
10 Posted by voltmer1 on 24 Apr, 2015 01:38 PM
Ryan, I've already re-published the base folder with no changes to the order on the navigation. I wonder if it's my format for the left-nav block? (posted earlier)
11 Posted by Ryan Griffith on 24 Apr, 2015 02:15 PM
Hi,
I am not seeing a sort in your Format, so you should be OK there. Can you confirm if the order appears correct in Cascade? If not, check your Index Block to make sure the sorting method is set to Folder Order and not something else like name or creation date.
Please let me know if you have any questions.
Thanks!
12 Posted by voltmer1 on 24 Apr, 2015 02:23 PM
Thanks Ryan! It was the index block for that navigation was set to "Alphabetical", not "Folder order".
13 Posted by Ryan Griffith on 24 Apr, 2015 02:36 PM
Not a problem at all. I am glad to hear you were able to track it down.
Once you do re-order the assets, be sure to re-publish the base folder so the changes are present on the live website.
I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.
Have a great day!
Ryan Griffith closed this discussion on 24 Apr, 2015 02:36 PM.