From 94db371234b33a2146092a1d954d79e03eb40d8a Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 10 Dec 2013 09:59:13 +1100 Subject: [PATCH] Ensures macro and urls are not parsed in the ItemRenderer when a content item is assigned since that parsing will occur with the value converters --- src/Umbraco.Web/umbraco.presentation/item.cs | 25 ++++++++++++++----- .../umbraco/templateControls/ItemRenderer.cs | 18 ++++++++++++- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/item.cs b/src/Umbraco.Web/umbraco.presentation/item.cs index 3adad53ac3..0920618f60 100644 --- a/src/Umbraco.Web/umbraco.presentation/item.cs +++ b/src/Umbraco.Web/umbraco.presentation/item.cs @@ -77,17 +77,30 @@ namespace umbraco } else { - if (elements[_fieldName] != null && !string.IsNullOrEmpty(elements[_fieldName].ToString())) + //check for published content and get its value using that + if (publishedContent != null) { - _fieldContent = elements[_fieldName].ToString().Trim(); + var pval = publishedContent.GetPropertyValue(_fieldName); + var rval = pval == null ? string.Empty : pval.ToString(); + _fieldContent = rval.IsNullOrWhiteSpace() ? _fieldContent : rval; } - else if (!string.IsNullOrEmpty(helper.FindAttribute(attributes, "useIfEmpty"))) + else if (elements[_fieldName] != null && string.IsNullOrEmpty(elements[_fieldName].ToString()) == false) + { + //get the vaue the legacy way (this will not parse locallinks, etc... since that is handled with ipublishedcontent) + _fieldContent = elements[_fieldName].ToString().Trim(); + } + + //now we check if the value is still empty and if so we'll check useIfEmpty + if (string.IsNullOrEmpty(_fieldContent)) { - if (elements[helper.FindAttribute(attributes, "useIfEmpty")] != null && !string.IsNullOrEmpty(elements[helper.FindAttribute(attributes, "useIfEmpty")].ToString())) + if (string.IsNullOrEmpty(helper.FindAttribute(attributes, "useIfEmpty")) == false) { - _fieldContent = elements[helper.FindAttribute(attributes, "useIfEmpty")].ToString().Trim(); + if (elements[helper.FindAttribute(attributes, "useIfEmpty")] != null && string.IsNullOrEmpty(elements[helper.FindAttribute(attributes, "useIfEmpty")].ToString()) == false) + { + _fieldContent = elements[helper.FindAttribute(attributes, "useIfEmpty")].ToString().Trim(); + } } - } + } } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs index 9676f1d184..f7da73ff3f 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs @@ -75,7 +75,18 @@ namespace umbraco.presentation.templateControls // handle text before/after xsltTransformedOutput = AddBeforeAfterText(xsltTransformedOutput, helper.FindAttribute(item.LegacyAttributes, "insertTextBefore"), helper.FindAttribute(item.LegacyAttributes, "insertTextAfter")); string finalResult = xsltTransformedOutput.Trim().Length > 0 ? xsltTransformedOutput : GetEmptyText(item); - writer.Write(TemplateUtilities.ResolveUrlsFromTextString(finalResult)); + + //Don't parse urls if a content item is assigned since that is taken care + // of with the value converters + if (item.ContentItem == null) + { + writer.Write(TemplateUtilities.ResolveUrlsFromTextString(finalResult)); + } + else + { + writer.Write(finalResult); + } + } catch (Exception renderException) { @@ -149,6 +160,11 @@ namespace umbraco.presentation.templateControls /// The item. protected virtual void ParseMacros(Item item) { + + //Don't parse macros if there's a content item assigned since the content value + // converters take care of that + if (item.ContentItem != null) return; + // do nothing if the macros have already been rendered if (item.Controls.Count > 0) return;