I've had some success with this approach (example used is for a footer but could easily be applied to a header):
- Create a Generic DD4T XML Page Template that Publishes a DD4T page with an XML extension (the extension itself is actually fairly arbitrary).
- Create a Generic DD4T Component Template with no specific view/controller/action.
- Create a Page for the footer in Tridion, add Component Presentations for the relevant parts of the footer. Define a convention for where this Page will be published (e.g.
- Create a LayoutController in your application and a Footer action.
Inject an IPageFactory into this controller and use this to resolve your page:
public ActionResult Footer()
var model = new FooterViewModel();
if (_pageFactory.TryFindPage("/_system/footer.xml", out page)
// map page to model
return PartialView("_Footer", model);
Then, in your layout, you just need to do this:
Obviously this will need adapting to your specific scenario (e.g. to make the footer page path configurable); but this gives you exactly the same setup for your footer view as for your Component Presentation views, with the exception being that the Page URL is preconfigured.
This is particularly convenient if you're using some kind of mapping framework to map Component Presentations to view models as your mapping code doesn't have to change.
It's generally best if you wrap everything up in one Component Presentation on this Page as you can then just map the first CP on the Page and treat the view like any other Component Presentation view.
If, however, you need more flexibility in terms of different Component Templates on the header/footer, you can pass
page to the view directly and then use
RenderComponentPresentations as if it was a normal Page Template. If you go down this route, you'll need to swap the Generic DD4T Component Template for "proper" CTs with associated views/actions.
I find that this is also quite intuitive for content editors as they can just treat the footer as "another page."