Sitecore.Layouts.RenderingReference[] renderings = Sitecore.Context.Item.Visualization.GetRenderings(Sitecore.Context.Device, true);
foreach (var rendering in renderings)
{
// Check if the rendering is an SXA rendering
if (rendering.RenderingItem != null && rendering.RenderingItem.InnerItem.TemplateName.Equals("Rendering Variant"))
{
// Get the rendering variant ID from the rendering settings
var variantId = rendering.Settings["Variation ID"];
// Get the rendering variant item based on the ID
var variantItem = Sitecore.Context.Database.GetItem(variantId);
// You can now access properties of the rendering variant item, such as its name
if (variantItem != null)
{
var variantName = variantItem["Name"];
// Do something with the rendering variant information
}
}
}