sitecoresitecore8sitecore-mvcglass-mapper

Sitecore glassmapper how to fetch the datasource from the rendering


need an suggestion on Sitecore rendering where i want to use glassmodel to render the item.

I have a page and that has many renderings and each renderings has data source associated with it.

I know that below statement will give me the Current context, not the datasource item.

var context = new SitecoreContext();
            Model = context.GetCurrentItem<HomePage>();

What is the best option to solve my query? I gave gone through this article. But i'm really not convinced with that method as i'm using IoC (Windsor Castle) and have to write Unit test cases for each method. I may have to mock these objects later. I'm looking for the approach where i will be using Interface not the class.

Appreciate your help.


Solution

  • If your controller is derived from GlassController you can use GetDataSourceItem<I..>(). That will give you the datasource.

    Please note: Glassmapper is now absolute. This class will be removed in Future Releases. CS0618 Warning.