9

What is the best approach for building navigation with DD4T and ASP.NET MVC?

From Tridion I was thinking to publish the Structure Groups as XML, including URIs for the Pages, and then in the MVC application to parse the XML, resolve the Page Links, and use a sitemap provider (or something like it).

Is there a better way to build the navigation? I found this article for a Sitemap provider, but anything better? http://edspencer.me.uk/2011/09/20/mvc-sitemap-provider-tutorial-2-breadcrumbs/

1 Answer 1

9

Rob,

There's a TridionSiteMapProvider as part of the DD4T.Mvc project, which can be used out of the box with the accompanying example TBB with generates a sitemap.

Unlike your article though, the sitemap for DD4T generally uses URLs as the editor sees them in Tridion, not controller/action style URLs you normally use with MVC.

The provider is activated by updating your web.config:

<system.web>
  <siteMap defaultProvider="TridionSiteMapProvider" enabled="true">
    <providers>
      <clear/>
      <add name="TridionSiteMapProvider" type="DD4T.Mvc.Providers.TridionSiteMapProvider, DD4T.Mvc"/>
    </providers>
  </siteMap>
</system.web>

The TBB is an "example" because generating a sitemap typically requires logic specific to what you need in your situation but as with non-DD4T applications, you could generate this from taxonomy or any other mechanism you wish.

Cheers

3
  • An alternative would be to write a SiteMapProvider which reads its input straight from the broker database. It could use taxonomies or structure groups (which are similar to taxonomies on the CD side anyway). In that case, questions like 'which structure groups are part of the navigation', or 'how should I order the items' should be answered in the provider. In the approach that Neil suggests, you typically put that logic in the TBB.
    – Quirijn
    Commented Mar 27, 2013 at 9:02
  • I notice that the TBB constructs the URL for the file in navigation at Publish time. CreateUrl(baseUrl, sg.Directory, p.FileName + "." + p.PageTemplate.FileExtension); Why not use a Page URI and dynamic linking?
    – robrtc
    Commented Mar 27, 2013 at 9:30
  • If presentation-server allows it (assuming yes with DD4T, right?), then sure. Nuno Linhares describes that approach in this SO answer. Commented Mar 28, 2013 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.