TIHIDI: Implement a simple view rendering in Sitecore MVC and Glass

This blog post will go through how I setup a basic View rendering using Glass Mapper Model.

Visit http://www.glass.lu/mapper/sc for more information on Glass Mapper for Sitecore.

TIHIDI: Stands for This Is How I Do It. I am going to write a series of blog posts going through how I do Sitecore related work. Hope it helps you!

Lets start by adding a simple template called TextBlock.

view1

Lets add some data we can use as a datasource.
view2

Once that is setup, lets add the Model and the Mapping in our projects.

Once that is done, lets add a view in the web project.

Add an associated View rendering in Sitecore and add it to the item you like, in my case I am adding it to the home item. Build and publish. Publish in Sitecore as well.

In a client browser it looks good.
view3

In the Page Editor, oops sorry Experience Editor, which took forever to load it looks good but I am unable to edit the content.
view4

If you have a need for this content to be editable you would need to do a couple of things. One, you would need to specify the Id attribute for the Model and two, you need to use Glass methods to make these fields editable.

Build and publish, load the page in Experience Editor and (after while) there ya have it!
view5

If you have any questions or concerns, please get in touch with me. (@akshaysura13 on twitter or on Slack).

2 comments

  • Derek Dysart 1 year ago

    Ask any Chicagoan what the name of the tallest building is, and they’ll still say “Sears Tower” despite is acutally being “Willis Tower” now. Likewise, it will always be the Page Editor to me. 🙂

    Like the series.

  • akshaysuraadmin 1 year ago

    Thank you!

Add your comment

Your email address will not be published.