By the time the below code is accessed in Controller/View Rendering, any personlization rules are applied.
So, the DataSource
and Item
properties point to the the datasource are the personalized ones configured for the rule that is applied.
Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.DataSource
Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.Item
Below code shows how to get the RuleList xml and pull the default DataSource out of it.
string text = rendering.Properties["RenderingXml"];
if (string.IsNullOrEmpty(text))
{
var renderingReference =
new RenderingReference(XmlExtensions.ToXmlNode(XElement.Parse(text)), <contextlanguage>, <contextdatabase>);
var DefaultDataSource = renderingreference.Settings.DataSource;
}
Once the Rendering reference is obtained, the default datasource can be pulled from its Settings.DataSource
property.
The order of DataSource for the rendering will be
- DataSource selected in the Action section of Rule that is applied
- The order of Default DataSource will be
- DS selected in the Action section
- If Action Section is empty, then DS selected from Rendering Parameters
- If none of them are set then
RenderingReference.Settings.DataSource
is empty. But the actual Rendering DataSource set to PageItem