3

We have to create Model classes for a Component which contains 2 levels of Component linking.

In the second level it allows multiple Component links where allowed Schemas are different for each Component.

How should we write the model classes in this scenario please suggest?

In the example site, ContentList Model class has itemsElementList field which is an Embedded Schema and the Link field is used for Component link within that. But in our case we have multiple Components added as links at 2nd level each Component Schema type is different.

6

How you model a Component Link in a DXA View Model depends on how you want to render the linked Component(s).

If you just want to render hyperlinks, you can map it to a propery of type Link (or a collection of Links).

If you want to embed (parts of) the linked Components in your view, you can map to a property of type EntityModel (or a collection of those).

  • Can you please explain in detail, how to map multiple entity models of different schema type to a single model field. – user2404968 Feb 16 '16 at 14:37
  • 1
    The trick is to make the View Model property of type EntityModel (which is an abstract class/interface implemented by all Entity Models). That allows the property to contain any kind of Entity Model (so for any Schema). You will have to ensure that a concrete subclass can be resolved through semantic mappings. An example of such a setup can be found in the Paragraph.Media property (MediaItem is an abstract base class of Image, YouTubeVideo, Download, etc. which are resolved through semantic mappings). – Rick Pannekoek Feb 16 '16 at 16:14
  • Thanks Rick the trick worked for us..we are able to display component link contents with multiple allowed schemas – user2404968 Feb 17 '16 at 17:52
  • 1
    Good to hear. Can you mark this as resolved, then? – Rick Pannekoek Feb 17 '16 at 18:18
  • Hi rick, we are facing issue in rendering the third level component linking.I applied the fix i did for resolving two level component links but it does not seems to work.Please suggest if the same will work for third level component linking? – user2404968 Feb 25 '16 at 15:55
0
  • You have to define model for each schema in your question, whether its embedded or component link.
  • Also in DD4T tbb Render Component Content make sure you are allowing the desired level of component linking.

pseudo example.

Class A
{
    public B Property1
}

Class B
{
    public C property1;
    public D property2;    
}

Class C
{
    public string name;

}

Class D 
{
    public string prop;
}
  • Can you please explain in detail, how to map multiple entity models of different schema type to a single model field – user2404968 Feb 16 '16 at 14:39
  • As i gave example. You just need to map property to semantics. It will do the magic. You can see existing example, which at least have 1 to 2 level of linking. Similarly you can do. Map each schema to separate class and use like egi i provided.. Have u tried anything yet?. Try and discuss your problem then. – Raj Kumar Feb 16 '16 at 16:39

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.