Surendra Sharma

Surendra Sharma

Search This Blog

Wednesday, June 5, 2013

Glass Library Implementation in Sitecore Project

1.    Install Package Managar in Visual Studio
a.    Go to Tools->Extension Manager-> click Online Gallery -> NuGet Package Manager. Download & install it
2.    Install Glass library
a.    Go to Tools-> Library Package Manager->Package Manager Console
Type command PM>"Install-Package Glass.Sitecore.Mapper" & press enter
3.    Create folder "Model" in your visual Studio project.
4.    Add cs file like "SitecoreHome.cs" in Model folder which map to content/template fields of sitecore


5.    Add following code in “Global.asax

public void Application_Start() {

var loader = new Glass.Sitecore.Mapper.Configuration.Attributes.AttributeConfigurationLoader(
            "WebApplicationRND.Model, WebApplicationRND");

Glass.Sitecore.Mapper.Context context = new Glass.Sitecore.Mapper.Context(loader);

  }

6.    Try to access it from web page code behind file as

Glass.Sitecore.Mapper.ISitecoreContext context = new Glass.Sitecore.Mapper.SitecoreContext();
var home = context.GetCurrentItem<WebApplicationRND.Model.SitecoreHome>();

Label4.Text = "<br> This is ---" + home.PageTitle + "----" + home.Created.ToString() + "---" + home.CreatedBy ;

Use LINQ with Glass

No comments:

Post a Comment