Tuesday, January 16, 2018

Passing Item Rendering Parameters To Sitecore MVC

Sitecore having functionality to pass the custom addition properties/parameters from item rendering to the Sitecore MVC view or code behind. This makes flexibility to the marketer or content author to make the custom functionality of any rendering on the basis of passed addition parameters. For example HTML Marquee, background Css etc.

There are two ways to use to achieve this functionality:
1) You can pass additional parameters under section Parameters that is shared field works on the basis of key and value. Both are Textboxes.
Example
Key:Background  and Value : Red
Prensentation -> Details -> Final Layout -> Rendering -> Edit
@Html.Sitecore().CurrentRendering.Properties["Background"] //cshtml
//or
RenderingContext.Current.Rendering.Properties["Background"] //controller code

2) Second approach you can use any Template as additional parameters which provide flexibility to working same as other item template. For this, first you need to create template and go the rendering which you applied on the Presentation. After that select that additional template on the "Parameter Template" Drop Down which you have created. Now you can use this template on the template and pass the values of this template as additional parameters to Sitecore MVC.

Cshtml
@{
    string BackgroundCss = string.Empty;
    var rncontrol = Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull;
    if (rncontrol != null)
    {
        var parms = rncontrol.Rendering.Parameters;
        BackgroundCss = parms["Background"];
    }
    <h4 class="@BackgroundCss">@Model.name</h4>
    <hr>
}

Monday, January 15, 2018

Sitecore APIs with Presentation & Layout Details

Coding for item Presentation Rendering with the use of Sitecore API. You can make it as customozied as per your requirement.Enjoy!!!







Setting Dynamic Datasource at runtime to the rendering