I have a Helix based solution using Glass mapper. I want to build a Feature module with a component that renders an item and its children with a controller rendering. Per Helix guidelines, my feature module defines "interface" templates for the item and its children and in the project layer, I have "concrete" templates which inherit the feature's interface templates. Is there a way to write Glass Mapper code (only in the Feature module) which will work with templates derived from the interface templates?
Feature module code:
[SitecoreType(true, "{152BC181-FF05-4FDD-863A-47557CDAB763}", TemplateName = "_RichTextList")]
public interface IDatasource : ISitecoreItem
{
}
[SitecoreType(true, "{1DE3EB16-98D4-4787-88CB-2E065E00B219}")]
public interface IDatasourceChild : ISitecoreItem
{
[SitecoreField("{4502C93C-FAA2-4FC5-8D3D-993B64E5E187}", SitecoreFieldType.RichText, FieldName = "Text", ReadOnly = true)]
string Text { get; set; }
}
public class DataSourceViewModel
{
public IDatasource Datasource { get; set; }
public IList<IDatasourceChild> Items { get; set; }
}
public class MyController : GlassController
{
public ActionResult MyComponent(IDatasource datasource)
{
var viewModel = new DataSourceViewModel
{
Datasource = datasource,
Items = datasource?.Children.OfType<IDatasourceChild>().ToList() ?? new List<IDatasourceChild>()
};
return View(viewModel);
}
}
The above code only works when the child items of the datasource use the interface template from the feature module, but not when it uses the "concrete" template from the project layer.