Skip to content

Instantly share code, notes, and snippets.

@trnktms
Last active June 1, 2016 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trnktms/0b71a48ec7d7057db9208dc273697336 to your computer and use it in GitHub Desktop.
Save trnktms/0b71a48ec7d7057db9208dc273697336 to your computer and use it in GitHub Desktop.
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