hardcoding a path in our breadcrumbs

matthew.wren's Avatar

matthew.wren

29 Apr, 2015 02:59 PM

We currently have a format that dynamically creates a breadcrumb path by pulling a page's and folder's display name and includes their links. I'm just wondering if there's a way to hardcode the very beginning of the path into the format? I ask because we are working on something else and we will be changing the display name of our root folder so it would be easier just to hardcode the root folder's name into the format since it's always the same.

I'm trying to see what I can do but I'm not certain where to make this change.

Here's a page with breadcrumbs and I want to hardcode "Home" into the path.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output indent="yes" method="xml"/>
    <!-- Define global stylesheet variables -->
    <xsl:variable name="default-page-name">index</xsl:variable>
    <xsl:variable name="use-folder-metadata">Yes</xsl:variable>
    <xsl:variable name="bread-crumb-separator"> &gt; </xsl:variable>
    <xsl:variable name="css-class">breadcrumb</xsl:variable>
    <xsl:variable name="current-page">
        <xsl:value-of select="//system-page[@current='true']/name"/>
    </xsl:variable>
    <!-- Create the outer HTML container for the bread crumbs trail -->
    <xsl:template match="system-index-block">
        
            <!-- Find the current page so that we can use the ancestor axis to return all of its parent pages -->
            <div class="breadcrumbs">
                <xsl:apply-templates select="//system-page[@current='true']"/>
            </div>
        
    </xsl:template>
    <xsl:template match="system-page">
        <!-- Get the count of all parent pages for subsequent if/else logic below -->
        <xsl:param name="count">
            <xsl:value-of select="count(ancestor::system-folder)"/>
        </xsl:param>
        <!-- Recur through all parent directories and target the default page for each one -->
        <xsl:for-each select="ancestor::system-folder">
            <!-- Confirm that the ancestor directory at least has an default page before trying to output any values -->
            <xsl:if test="display-name and display-name != '/'">
                <xsl:choose>
                    <xsl:when test="$use-folder-metadata='Yes'">
                        <xsl:choose>
                            <xsl:when test="$current-page=$default-page-name">
                                <xsl:choose>
                                    <!-- Output hyperlinks for the default page in each ancestor directory -->
                                    <xsl:when test="position() &lt; $count">
                                        <a>
                                            <xsl:attribute name="href">[system-asset]<xsl:if test="path != '//'"><xsl:value-of select="path"/></xsl:if><xsl:text>/</xsl:text><xsl:value-of select="$default-page-name"/>[/system-asset]</xsl:attribute>
                                            <xsl:value-of select="display-name"/>
                                        </a>
                                        <xsl:value-of select="$bread-crumb-separator"/>
                                    </xsl:when>
                                    <!-- If the current page is an default page, make sure to not hyperlink the last value in the bread crumbs since you're already there -->
                                    <xsl:otherwise>
                                        <xsl:variable name="name" select="display-name"/>
                                    <xsl:choose>
                                    <xsl:when test="contains($name,'&lt;br/&gt;')">
                                    <xsl:value-of select="substring-before($name, '&lt;br/')"/><xsl:text> </xsl:text>
                                    <xsl:value-of select="substring-after($name, 'br/&gt;')"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                    <xsl:value-of select="display-name"/>
                                    </xsl:otherwise>
                                    </xsl:choose>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:when>
                            <!-- If the current page is not an default page, be sure to output a hyperlink to the sibling default page in the directory-->
                            <xsl:otherwise>
                                <xsl:choose>
                                    <xsl:when test="position() &lt;= $count">
                                        <a>
                                            <xsl:attribute name="href"> [system-asset]<xsl:if test="path != '//'"><xsl:value-of select="path"/></xsl:if><xsl:text>/</xsl:text><xsl:value-of select="$default-page-name"/>[/system-asset]</xsl:attribute>
                                            <xsl:value-of select="display-name"/>
                                        </a>
                                        <xsl:value-of select="$bread-crumb-separator"/>
                                    </xsl:when>
                                </xsl:choose>
                                <!-- Be sure to output the current page display name -->
                                <xsl:if test="@current = 'true'">
                                
                                    <xsl:variable name="name" select="system-page[@current='true']/display-name"/>
                                    <xsl:choose>
                                    <xsl:when test="contains($name,'&lt;br/&gt;')">
                                    <xsl:value-of select="substring-before($name, '&lt;br/')"/><xsl:text> </xsl:text>
                                    <xsl:value-of select="substring-after($name, 'br/&gt;')"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                    <xsl:value-of select="system-page[@current='true']/display-name"/>
                                    </xsl:otherwise>
                                    </xsl:choose>
                                
                                </xsl:if>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:choose>
                            <xsl:when test="$current-page=$default-page-name">
                                <xsl:choose>
                                    <!-- Output hyperlinks for the default page in each ancestor directory -->
                                    <xsl:when test="position() &lt; $count">
                                        <a>
                                            <xsl:attribute name="href"> [system-asset]<xsl:value-of select="system-page[name=$default-page-name]/path"/> [/system-asset]</xsl:attribute>
                                            <xsl:value-of select="system-page[name=$default-page-name]/display-name"/>
                                        </a>
                                        <xsl:value-of select="$bread-crumb-separator"/>
                                    </xsl:when>
                                    <!-- If the current page is an default page, make sure to not hyperlink the last value in the bread crumbs since you're already there -->
                                    <xsl:otherwise>
                                        <xsl:variable name="name" select="system-page[name=$default-page-name]/display-name"/>
                                    <xsl:choose>
                                    <xsl:when test="contains($name,'&lt;br/&gt;')">
                                    <xsl:value-of select="substring-before($name, '&lt;br/')"/><xsl:text> </xsl:text>
                                    <xsl:value-of select="substring-after($name, 'br/&gt;')"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                    <xsl:value-of select="system-page[name=$default-page-name]/display-name"/>
                                    </xsl:otherwise>
                                    </xsl:choose>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:when>
                            <!-- If the current page is not an default page, be sure to output a hyperlink to the sibling default page in the directory-->
                            <xsl:otherwise>
                                <xsl:choose>
                                    <xsl:when test="position() &lt;= $count">
                                        <a>
                                            <xsl:attribute name="href"> [system-asset]<xsl:value-of select="system-page[name=$default-page-name]/path"/> [/system-asset]</xsl:attribute>
                                           <xsl:value-of select="system-page[name=$default-page-name]/display-name"/>
                                        </a>
                                        <xsl:value-of select="$bread-crumb-separator"/>
                                    </xsl:when>
                                </xsl:choose>
                                <!-- Be sure to output the current page display name -->
                                
                                <xsl:variable name="name" select="system-page[@current='true']/display-name"/>
                                    <xsl:choose>
                                    <xsl:when test="contains($name,'&lt;br/&gt;')">
                                    <xsl:value-of select="substring-before($name, '&lt;br/')"/><xsl:text> </xsl:text>
                                    <xsl:value-of select="substring-after($name, 'br/&gt;')"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                    <xsl:value-of select="system-page[@current='true']/display-name"/>
                                    </xsl:otherwise>
                                    </xsl:choose>
                               
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
  1. 1 Posted by Ryan Griffith on 29 Apr, 2015 03:14 PM

    Ryan Griffith's Avatar

    Hi Matthew,

    You should be able to simply add the link within your system-index-block template, right before you call the <xsl:apply-templates> to output the hierarchy. Additionally, you could check the calling page to make sure you don't end up outputting a link for Home more than once (that is if you are outputting breadcrumbs on the base folder's index page).

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by matthew.wren on 29 Apr, 2015 03:24 PM

    matthew.wren's Avatar

    No problem with putting in the home link in the template but I tried modifying the index block to get rid of the extra Home link and unable to do so. I attached the breadcrumbs as it currently is and the current index block.

  3. 3 Posted by Ryan Griffith on 29 Apr, 2015 03:29 PM

    Ryan Griffith's Avatar

    Hi Matthew,

    My apologies, didn't realize the Format was already generating the link. In that case, perhaps try tweaking the XPath of your <xsl:for-each> to the following to filter out the top level folder all-together:

    <xsl:for-each select="ancestor::system-folder[path != '//']">
    

    Additionally, you can remove the <xsl:if> within the loop when outputting the link since your loop will no longer contain this folder.

    Please let me know if you have any questions.

    Thanks!

  4. 4 Posted by matthew.wren on 29 Apr, 2015 03:32 PM

    matthew.wren's Avatar

    That worked wonderfully! Thank you so much.

  5. 5 Posted by Ryan Griffith on 29 Apr, 2015 03:49 PM

    Ryan Griffith's Avatar

    Not a problem at all, Matthew, thank you for following up. I am glad to hear the changes did the trick.

    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!

  6. Ryan Griffith closed this discussion on 29 Apr, 2015 03:49 PM.

  7. matthew.wren re-opened this discussion on 06 May, 2015 06:49 PM

  8. 6 Posted by matthew.wren on 06 May, 2015 06:49 PM

    matthew.wren's Avatar

    Hey Ryan,

    I just noticed something with the breadcrumbs. If the system-page title is index it will exclude the display name of the page within the crumb trail. Would <xsl:for-each select="ancestor::system-folder[path != '//']"> affect this?

  9. 7 Posted by Ryan Griffith on 07 May, 2015 06:18 PM

    Ryan Griffith's Avatar

    Hi Matthew,

    I'm not sure if I am following here. I don't see any reference in your Format for a page's title. Can you elaborate a bit more?

    Thanks!

  10. Ryan Griffith closed this discussion on 27 May, 2015 07:42 PM.

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

 

26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM