This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static HtmlString RenderPersonalizationRuleHightlight<T>(this HtmlHelper<T> htmlHelper) | |
{ | |
var result = new MvcHtmlString(string.Empty); | |
if (!Sitecore.Context.PageMode.IsExperienceEditor) | |
{ | |
return result; | |
} | |
var sitecore = htmlHelper.Sitecore(); | |
if (sitecore.CurrentRendering == null || sitecore.CurrentRendering.Properties == null) | |
{ | |
return result; | |
} | |
string rulesString = sitecore.CurrentRendering.Properties["PersonlizationRules"]; | |
if (string.IsNullOrEmpty(rulesString)) | |
{ | |
return result; | |
} | |
try | |
{ | |
var rules = XElement.Parse(rulesString); | |
var elements = rules.Descendants().Elements("rule").ToList(); | |
if (elements.Count() > 1 || elements.Any(e => e.Attribute("uid").Value != ID.Null.ToString())) | |
{ | |
result = new MvcHtmlString("<div class='page-editor-dach-highlight'>This rendering uses personalization rules.</div>"); | |
} | |
} | |
catch (Exception e) | |
{ | |
Sitecore.Diagnostics.Log.Error("An error occured: ", e, typeof(HtmlHelperExtension)); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment