Many times that we would like to achieve that personalization should apply with minimal changes. To do the same content authors have to apply personalization rule on each items. Many times content author have to apply personalization rule in parent item and same rules needs to apply in it’s all child element which looks redundant work.
We can use this approach to get rid of this burden from Content author with creating a new component to add all personalized rule in it and on the child element we don’t need to add personalized rule if it same. We can add the same personalized component (newly created component) on the child element if it have to add different personalized rule. To achieve this we have to add logic in our layout page to check whether personalized component is added or not. If it is not added then we can traverse to it’s parent node till we reach to home node of Sitecore content (start item path of application). Wherever we are able to retrieve the personalized component, we have to consider that component and have to apply personalized rule.
After implementing this, you can find that personalized rule won’t get work and you will able to find only default rule applying which is expected. Sitecore personalization rule will work only for current context, in this approach your current context of item is your child element and you are trying to retrieve the personalized rule from your parent item. But this can be achievable by simply using below code.
var rendering = referenceItem.Visualization.GetRenderings(Sitecore.Context.Device, true).ToList().Where(t => t.RenderingID.ToString() == “Rendering Item Guid”).FirstOrDefault();
var bookingConfigDataSrc = rendering.GetPersonalizationDataSourceItem(referenceItem);
————————————————————————————
public static string GetPersonalizationDataSourceItem(this RenderingReference reference, Item propertPageContext)
{
List<Item> list = new List<Item>();
var defaultDataSource = reference.Settings.DataSource; // Default DataSource
if (reference != null && reference.Settings.Rules != null && reference.Settings.Rules.Count > 0)
{
RuleList<ConditionalRenderingsRuleContext> rules = reference.Settings.Rules;
if (rules.Count != 0)
{
List<RenderingReference> references = new List<RenderingReference>();
references.Add(reference);
ConditionalRenderingsRuleContext context = new ConditionalRenderingsRuleContext(references, reference);
context.Item = propertPageContext;
reference.Settings.Rules.RunFirstMatching(context);
if (!string.IsNullOrEmpty(reference.Settings.DataSource))
defaultDataSource = reference.Settings.DataSource; // Personalized DataSource
}
}
return defaultDataSource;
}
Try to use this logic to reduce the burden of content author to doing redundant work and
I have observed that of all kinds of insurance, medical care insurance is the most questionable because of the turmoil between the insurance plan company’s necessity to remain profitable and the client’s need to have insurance cover. Insurance companies’ earnings on health and fitness plans are incredibly low, therefore some providers struggle to make a profit. Thanks for the ideas you reveal through this blog.
Everything is very open with a really clear clarification of the issues. It was definitely informative. Your site is very helpful. Thanks for sharing!