1

I have an Item in Sitecore, and I know it's derived from a certain base template. I have that base template ID, but I want to get the instance of this base template that is part of my page. I want it as an item, so for example I can get the ID of the template internal of the page.

To be more clear:

  • Page called A1 of template A
  • Template A has as base template the template B
  • B is part of page A1 as an instance called B1 (field values specific for the page A1)

How can I get B1 as stand alone Item/ID?
I need to build on it an EditFrame to use in experience editor. Have an EditFrame on this base template instance avoid problems with Synonym fields in the Page.
Any help is appreciated.
Thanks.

enter image description here

The component in red square is inherited from a base template, but I know it has an specific id (from yml of the page). I need to take that ID. and not the base template ID.

2
  • 1
    Best add some screenshots. I'm lost with with all the "templates" and "instances" in your question ;)
    – Marek Musielak
    Nov 19, 2019 at 14:54
  • add an image hope it helps @MarekMusielak Nov 19, 2019 at 15:02

1 Answer 1

2

I think there is some confusion here about how the template inheritance works in Sitecore.

Let's say you have Template B with Field BB, and Template A that has Field AA. Template A also inherits Template B.

Now when you create a Page based on Template A, the page will have 2 fields, AA and BB.

To read those fields, you would just get the Page item:

var page = Sitecore.Context.Item;
var fieldAA = page["AA"];
var fieldBB = page["BB"];

That it, its all you need to do.

There is no "instance" of template B created, the templates just define the fields and inheritance. But once a page item is created, its just a single item with all the fields on it.

Now lets say I have a Component that only looks at field BB - that's fine, you don't need an item Id, you would either use the Context.Item if you want the current page to be the datasource, or you would use the rendering item if you want the author to create a datasource item. Either way, once you have the main item created from template A, you are good. You don't need to do anything else to get the field BB

2
  • Sorry for the misunderstanding I write a reply to my question Nov 19, 2019 at 16:43
  • you are right, I believed that the reasoning that applies to renderings was also valid for the base temlates in the yml of the item. In the YML I can see the rendering id and the rendering instance on my page, it's not the same for the base templates. To be more clear I report a little snippet <r ds="{C2AE6935-8144-458E-B96E-DD3AB3C57EDE}" id="{E74ABF54-3D43-469C-A1F3-5C785382233A}" par="" ph="Search" uid="{9C8A45F2-7008-42C1-8B8A-80A88825C1D8}" /> Here id is the ID of the rendering, and uid is the instance of the rendering in the page. Sorry for the misunderstanding. Nov 19, 2019 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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