Friday, 9 June 2017

Sitecore Renderings

Sitecore renderings are the way developers can render a page or a part of a page in Sitecore.  
Sitecore has many different types of renderings but when we work with MVC, the two main renderings. 
  • view renderings 
  • controller renderings
In View Rendering,
View rendering can be used for components that have no logic in it. Simply view rendering is like calling a partial view in MVC, basically, it doesn't have a controller.  View rendering works with a .cshtml view file and registering it with Sitecore. 

Go to Layouts->Renderings section, right click on Renderings and select Insert->View Rendering. Give some name as "MyviewRendering" and with below mentioned field values:
  1. Path : Path to the razor view file i.e., “/Views/MyviewRendering.cshtml“.
  2. Model : Click on insert link and select the sitecore Model we have created ‘MySitecoreModel’.
  3. PlaceHolder : This is the placeholder in the Layout file where this view rendering should be rendered.
  4. Template : this is the template where this view use the fields for using to create any item.
In Controller rendering, 
Controller rendering, has a controller and subsequently needs a little bit more configuration and code. controller rendering specifies a controller name and an action name 

 Create Controller name with MyController.cs
 Create View for that controller with named MyView.cshtml

Go to Layouts->Renderings, right click on Renderings, click on Insert->Controller Rendering.  Give some name as "MycontrollerRendering" and with below mentioned field values:
  1. Controller: My, Controller Action: Action(Method) Name
  2. Save and publish the item.
How to use rendering in any page(Item) :

  1.  Select any item in home node.
  2.  Go to Presentation->Detail 

 Layout Detail Popup will Appear. You Can Add/Edit your rendering here with placeholder.


Comments and suggestions are most welcome. Happy coding!  

No comments:

Post a Comment