Is there a way to identify current layout details with renderings?

James: 19 May 2022

I got a scenario where I have different layouts Layout1, Layout2, so on...I have a renderings which is shared among this layouts. Layout1- Rendering -R1 Layout2-Rendering-R1 and so.

Now I have situation where I want to identify the layout name or details within this rendering R1. I know this is not good idea still is there any way to refer the details of layout within renderings.

Paisley: 19 May 2022

You can access the layout in your code by using Sitecore.Context.Item.Visualization.Layout (example for context item). This will give you a LayoutItem that gives you access to the name, physical file, ...