Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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