Dynamic Menu Title (and breadcrumb trail)

Topics: General, Troubleshooting
Oct 10, 2011 at 6:27 PM

I have a products details page that I'm working on that I'd like to dynamically set the Menu Title for. The reason is that it will show up in things like the Bread Crumb trail.

Rather than have:

Home > Products > Details

I'd like:

Home > Products > My Awesome Widget

My initial thoughts are :

DataConnection conn = new DataConnection();

conn.SitemapNavigator.CurrentPageNode.MenuTitle = "My Awesome Widget";
        

However, the CurrentPageNode is Read-Only (As I Suppose it should be as I don't want to "change" the node's menu title... just make it dynamic for the current request.

Any ideas on the best way to access (and make dynamic) the Site Map Breadcrumbs?

Oct 10, 2011 at 6:39 PM

using the standard asp.net SiteMapProvider makes this much easier since its providerbased and made with extendability in mind.

protected override string Title
{
   get
   {
      if (// check_something_id_or)
      {
          return "My Awesome Widget";
      }

      return base.Title;
   }

   set { base.value = value; }
}

You can also make the node write-able like this

private string _title = null;
protected override string Title
{
   get
   {
      return _title ?? base.Title;
   }

   set { _title = value; }
}

Then you can do exactly what you want at runtime

SiteMap.Provider.CurrentNode.Title = "My Awesome Widget";

The C1 Contrib project includes a fully functional SiteMapProvider that you would use and extend from.

Oct 12, 2011 at 4:58 PM

I'll have to look into the C1 Contrib project. I have kind of avoided it as I didn't want to bolt on something that changes a lot of the functionality. Does the C1 Contrib project "enable" additional functionality or does it fundamentally change it? Can you point me to the best source of documentation and examples?

Oct 13, 2011 at 7:06 AM

Its all added functionality that you can enable and disable as you like. There have been some issues with NicerUrls where Composite's Blog and News package handled PathInfo incorrectly and would therefor break.

Since the end of september i splitted the different functionality into different packages so its not a all or nothing anymore, but you can pick what you like. The package you would be interested in is SiteMapProvider which contains a full C1 provider that is production ready and is in use on sites like http://www.sermersooq.glhttp://www.logbuy.dk/ and http://www.xstream.dk/.

There is unfortunately not any functions that expose it to XSLT but that would be easy to do if its needed. Documentation wise its pure plug and play. You register it in web.config, and then you can use it right away from asp.net code

<system.web>
    <siteMap defaultProvider="CompositeC1">
      <providers>
        <add name="CompositeC1" type="CompositeC1Contrib.Web.CompositeC1SiteMapProvider, CompositeC1Contrib" />
      </providers>
    </siteMap>
  </system.web>

 

To do the trick described above, you would subclass the CompositeC1SiteMapNode to make the Title writeable as described here, and CompositeC1SiteMapProvider so it would return your new Node-class. And then you would go and register your own new provider instead. But thats all standard asp.net stuff clearly documented by Microsoft http://msdn.microsoft.com/en-us/library/system.web.sitemapprovider.aspx.

I would be happy to help you out in both doing the subclassing and exposing it to xslt if needed. You can always write me on pauli [at] burningice [dot] dk

Oct 13, 2011 at 7:18 AM

Another approach to dynamically alter the SiteMap nodes at runtime, without having to subclass the provider is described here http://msdn.microsoft.com/en-us/library/ms178425.aspx

Dec 28, 2013 at 6:54 PM
Is this information still relevant? Does 4.1 version of C1 use same approach? .. How is prefered way to alter dynamic menu title now? Is it possible to alter breadcrumb items by completely different 'path' ?
Developer
Dec 28, 2013 at 8:34 PM
Dec 28, 2013 at 10:41 PM
@wysocki I fail to see how that last link explains how to render titles of non-pages.

@JaZGo If you wan't to render your breadcrumb and menus solely based on the SiteMap, then this is still exactly the same approach. Remember that 4.1 still uses the same underlying Asp.Net SiteMap technology so all that is written in these links still apply
Dec 30, 2013 at 11:52 AM
Thank you.

Propably I will need some reorganization in my C1 solution. I have breadcrums as razor function and sitemap is resolved even before Page_Init in my user control (which is displaying logic put on C1 page as UserControl). So when I register new event handler for SiteMap.SiteMapResolve its too late I think.

Can I expect this will be working when breadcrumb will be aspx user control too? There will be chance to actually draw path after registering sitemap resolve handler in another user control I hope.

Or am I missing something basic? :)
Dec 30, 2013 at 8:19 PM
You should register your handler in your global.asax or via ApplicationStartup (http://docs.composite.net/Functions/Composite-C1-API/ApplicationStartup)