YesGenesisCamel
YesGenesisCamel

Reputation: 183

Shared content between templates

I would like to share content (essentially blocks of html) between templates.

For example, suppose I have a common footer section with a graphic or two, text and links to 'about us', 'contact us' and so on. I have different templates for different page layouts, but they all require this footer. So far I can think of three ways :

  1. Nesting templates : ie have a master one which has the footer content, then a child one for each layout, then the actual page template, but this could get tricky if some pages need a different footer
  2. Using a Partial View to hold the footer content and using @Html.Partial() to pull in the partial view on the various templates
  3. Create a settings document with the footer content and use Umbraco.Content() to fetch the footer property

Is any of these the recommended process (and are there any pitfalls?) or is there a better way?

Upvotes: 1

Views: 1083

Answers (1)

Tim
Tim

Reputation: 4257

I would normally do one of the following:

  • Have properties on the homepage for the footer links etc (in a separate tab) and pull in the values into the footer partial, this way you only have to set it once, rather than having it on every page
  • Have a Site Settings node at the same level as the home page and pull the values from there into the footer partial

That seems to be fairly standard from most of the Umbraco sites that I've worked on. I wouldn't have all of the properties on each page, unless you need a unique footer each page for some reason.

For example, lets say you add a tab called "Footer Settings" to the Home Page DocType with a single string property with the alias "copyRightNotice" and then you want to display that in a partial, your partial might look something like:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
    var rootPage = Model.Content.AncestorOrSelf(1);
    <h3>@rootPage.GetPropertyValue("copyRightNotice")</h3>

}

Upvotes: 0

Related Questions