0

I have a Template for Page and in my layout, I have provided placeholder let’s say for example Header.

I am previewing my page and trying to debug my component view of the Header, I am trying to get the Header item object and it’s fields associated with it. I am always getting the page item. Basically, I would like to know how to get the associated component items inside the page?

var item = Sitecore.Context.Item["Header"]; 

This returns null

var item = Sitecore.Context.Item

This returns the page item.

However, I would like to get my component item Header

Could you help me with some guidance?

  • Are you try to get the datasource of your header rendering. – Andi AR Jul 4 at 12:55
  • Yes Andi.. trying to loop through the fields. I am able to get the field values in view using html helper though. – user1428019 Jul 4 at 14:02
0

You can use DataSource to point you header item:

var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource;
    var dataSource = Sitecore.Context.Database.GetItem(dataSourceId);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.