Using this code I managed to change the renderings on the current item. However this changed it permenantly in Sitecore (the changes were could be seen in the CMS) and not tempo
Sitecore constructs the rendering controls and inserts them into the page very early in the ASP.NET Webforms lifecycle. It's not likely you can easily do this on the layout itself. However, if you can evaluate your conditions outside the page (e.g. by examining the item itself), you can probably do this in the insertRenderings
pipeline.
Use ILSpy or another decompiler to check out Sitecore.Pipelines.InsertRenderings
and Sitecore.Pipelines.InsertRenderings.Processors
. As with other pipelines, the order of execution of these processors is defined in Web.config. You will want to add a new processor after AddRenderings which evaluates your conditions (likely examining args.ContextItem
) and then modifies args.Renderings
as needed.
In your previous question you were just looking to remove sublayouts. That should be fairly easy here. Adding different sublayouts is more difficult since you would need to construct a RenderingReference
. This may require that you actually create the XML definition needed for its constructor. Or, if you have another item that defines the desired new layout, consider just changing args.ContextItem
earlier in the pipeline.