I want to access the rendering context in the getLookupSourceItems pipeline.

public void Process(GetLookupSourceItemsArgs args)
    var rc = Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull;

But I am getting null value in the RenderingContext.

Any suggestions how can I get the rendering context in the getLookupSourceItems pipeline

  • 1
    The reason why you are getting null is because the Rendering Context is getting called after the getLookupSourceItems pipeline. Can you explain a little more on what you are trying? Ideally there should not be a need for getting the Rendering Context in getLookupSourceItems Pipeline as this pipeline is used for setting the data sources in templates. Are you trying to create a custom field? – Sumit Upadhyay Oct 22 '19 at 7:17
  • @sumit yes i am creating a custom field. I need to. Check current rendering’s datasource and then get the field value from the datasource and assign to the custom field – user2980 Oct 22 '19 at 11:00
  • Then you don't need to call getLookupSourceItems pipeline. You can create the custom item at runtime and then populate the field value by using Security Disabler and assigning the field value like item.Fields["field name"].Value = "your value" – Sumit Upadhyay Oct 22 '19 at 12:13

Apologies for the Short answer.

What you can try to implement is to use PageContext.Current.Item which will give you the Current page item or RenderingContext.Current.Rendering.Item

Hope this helps!

  • Based on his description, RenderingContext.Current will throw InvalidOperationException when CurrentOrNull is null. – Roland Mar 30 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy