2

I have to map a class with more than one template in GlassMapper. My code is like below.

[SitecoreType(TemplateId = "{6173F07E-BC5B-4409-A75A-DF1B0D117C41}", AutoMap = true, EnforceTemplateGlass.Mapper.Sc.Configuration.SitecoreEnforceTemplate.Template)] 

public class ResourceListings : MSEntity{
 public virtual ID Id { get; set; }
        [SitecoreField("Title")]
        public virtual string Title { get; set; }
}

I tried to pass more than one Template Id using pipe like

[SitecoreType(TemplateId = "{6173F07E-BC5B-4409-A75A-DF1B0D117C41}|{3175F07E-BC5B-5409-A75A-CF1B0b117C41}",

in above attribute but it throws error. Is there a way to achieve the same.

3

As per my knowledge there is no method to achieve your functionality in this way, only way is to use the inheritance by creating multiple class/interface. Since C# doesn't support multiple inheritance in class but you can achieve this using interface. I have never use multilevel inheritance for this but I guess that is also an option for this.

An example of interface, if I have a content page that inherits my IPageTitles template and an IMetadata template then my Content interface can inherit both:

public interface Content : IPageTitles, IMetadata{
}

and each Interface will have its own [SitecoreType()] Attribute.

An alternative is to use a single class model. The model contains just the properties we need to render. The model is also responsible for retrieving the ancestor items removing the need for any additional code.

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.