0
votes

I want to display my header logo on all pages from a master template, but I am having trouble getting the media URL from the document type.

My header logo resides in this content node: http://i.imgur.com/QuugP1J.png

Which has the template set as master.

The document type for the page is located here in the tree: http://i.imgur.com/6XZbecu.png

All my templates inherit from a single master template, where I want to display the header logo, but for some reason it won't display it when i insert the code for retrieving media items.

@{
  var typedMediaPickerSingle = Model.Content.GetPropertyValue<IPublishedContent>("headerLogo");
  if (typedMediaPickerSingle != null)
  {
    <a href="index.html"><img src='@typedMediaPickerSingle.Url" style="width:320px" alt="@typedMediaPickerSingle.GetPropertyValue("headerLogo")' /></a>
  }
}   
1

1 Answers

0
votes

If you want to get your content from a parent node don't use the current node Model.Content but traverse the nodes like this:

var languageNode = Model.Content.AncestorOrSelf(2);
var typedMediaPickerSingle = languageNode.GetPropertyValue<IPublishedContent>("headerLogo");

The "2" in the AncestorOrSelf method is the level to want to reach.