From 4d5f142a30c0f8615b9eab411c8ff37a8a95fe41 Mon Sep 17 00:00:00 2001 From: pgregorynz Date: Wed, 7 Nov 2012 21:19:35 -1000 Subject: [PATCH] fix for ItemRenderer.cs to work with Partials --- src/Umbraco.Web/UmbracoHelper.cs | 7 +++ .../umbraco/templateControls/ItemRenderer.cs | 49 +++++++++++-------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/Umbraco.Web/UmbracoHelper.cs b/src/Umbraco.Web/UmbracoHelper.cs index fc7debaecd..e8b5c81562 100644 --- a/src/Umbraco.Web/UmbracoHelper.cs +++ b/src/Umbraco.Web/UmbracoHelper.cs @@ -249,6 +249,8 @@ namespace Umbraco.Web attributesForItem.Add(i.Key, i.Value); } + + var item = new Item() { //NodeId = currentPage.Id.ToString(); @@ -256,6 +258,11 @@ namespace Umbraco.Web TextIfEmpty = altText, LegacyAttributes = attributesForItem }; + + //this is here to figure out if this request is in the context of a partial + if (_umbracoContext.PublishedContentRequest.PublishedContent.Id != _currentPage.Id) + item.NodeId = _currentPage.Id.ToString(); + var containerPage = new FormlessPage(); containerPage.Controls.Add(item); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs index 1d7371c5ac..8ef29fbb15 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs @@ -96,27 +96,36 @@ namespace umbraco.presentation.templateControls int? tempNodeId = item.GetParsedNodeId(); if (tempNodeId != null && tempNodeId.Value != 0) { - string currentField = helper.FindAttribute(item.LegacyAttributes, "field"); + + //moved the following from the catch block up as this will allow fallback options alt text etc to work + + page itemPage = new page(content.Instance.XmlContent.GetElementById(tempNodeId.ToString())); + tempElementContent = new item(itemPage.Elements, item.LegacyAttributes).FieldContent; + + /*removed as would fail as there is a incorrect cast in the method called. + Also the following code does not respect any of Umbraco Items fallback and formatting options */ + + //string currentField = helper.FindAttribute(item.LegacyAttributes, "field"); // check for a cached instance of the content - object contents = GetContentFromCache(tempNodeId.Value, currentField); - if (contents != null) - tempElementContent = (string)contents; - else - { - // as the field can be used for both documents, media and even members we'll use the - // content class to lookup field items - try - { - tempElementContent = GetContentFromDatabase(item.LegacyAttributes, tempNodeId.Value, currentField); - } - catch - { - // content was not found in property fields, - // so the last place to look for is page fields - page itemPage = new page(content.Instance.XmlContent.GetElementById(tempNodeId.ToString())); - tempElementContent = new item(itemPage.Elements, item.LegacyAttributes).FieldContent; - } - } + //object contents = GetContentFromCache(tempNodeId.Value, currentField); + //if (contents != null) + // tempElementContent = (string)contents; + //else + //{ + // // as the field can be used for both documents, media and even members we'll use the + // // content class to lookup field items + // try + // { + // tempElementContent = GetContentFromDatabase(item.LegacyAttributes, tempNodeId.Value, currentField); + // } + // catch + // { + // // content was not found in property fields, + // // so the last place to look for is page fields + // page itemPage = new page(content.Instance.XmlContent.GetElementById(tempNodeId.ToString())); + // tempElementContent = new item(itemPage.Elements, item.LegacyAttributes).FieldContent; + // } + //} } }