Developer forum

Forum » CMS - Standard features » RE: Breadcrumb Trail

RE: Breadcrumb Trail

Ian McKay
Reply

Hi all,

I have a little question about a breadcrumb trail I'm trying to implement on a project. Basically I have added the following code to my page templates.

---------

<div class="crumbtrail">
<p><a href="/">PGL</a><span class="dwnavigation" id="CrumbTrailTextLinks" data-settings="startlevel:1;endlevel:99;expandmode:All;includemode:all;sitemapmode:true;template:Breadcrumb.xslt;"></span></p>
</div> <!-- crumbtrail -->

---------

I did it this way to expose the full path to the template as some pages are held in folders within the tree structure that are hidden and I noticed that if i didn't do it this way the hidden pages stopped the breadcrumb from displaying any pages beyond these hidden pages.

I really didn't want to display the hidden pages and just display the full path, minus the hidden pages, in the breadcrumb trail.

Hope this makes sense.

Cheers,

Ian


Replies

 
Mikkel Ricky
Reply

The xml used to render the navigation does not contain information on whether a page has "Hide in menu" set or not – these pages should not appear in the xml for obvious reasons.

However, when actually including hidden pages in your navigation, you can use a cool trick find out if a page is hidden or not: Use the Dynamicweb API in a piece of C# code in your xslt.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"	xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts">
  <!-- @see http://msdn.microsoft.com/en-us/library/533texsx%28VS.71%29.aspx -->

  <msxsl:script language="C#" implements-prefix="user">
    <msxsl:assembly name="Dynamicweb" />
    <![CDATA[
// Use the Dynamicweb API to find out if a page has "Hide in menu" set
public bool PageIsHiddenInMenu(int pageId) {
  var page = Dynamicweb.Frontend.Page.FindPage(pageId);
  return page != null && !(bool)page.Values["pageactive"];
}
]]>
  </msxsl:script>

  <xsl:template match="/NavigationTree">
    <xsl:if test="count(//Page) &gt; 0">
      <ul>
        …
        <xsl:apply-templates select="//Page[@InPath='True' and not(user:PageIsHiddenInMenu(@ID))]">
          …
        </xsl:apply-templates>
      </ul>
    </xsl:if>
  </xsl:template>

  …
</xsl:stylesheet>

Best regards,
Mikkel

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Wouldn't that hurt performance? Isn't this doing a database lookup for each page in the navigation tree?

Imar

 
Mikkel Ricky
Reply

No, Frontend.Page.FindPage uses an internal cache (in memory) to get the page by id. I was going to mention this, but apparently forgot before hitting the submit button. 

Thanks for asking (and reminding me).

Best regards,
Mikkel

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Ah, thanks for clearing that up.

Imar

 
Remi Muller
Reply

I would unset the (hidden) page attribute "show in breadcrumb trail" and use the following in your xslt:

<xsl:apply-templates select="//Page[@InPath='True' and @ShowInLegend='True']" />

 

This should give better control if you want to see a page in the breadcrumb or not.

 

You must be logged in to post in the forum