Sitecore Rendering Parameters 

Rendering parameters can be used to pass parameters to sitecore presentation components. They are used to control the presentation of a dynamic component from page editor. Here’s the quick summary of how to implement a parameters template:

  • Create a parameters template data template that inherits from the System/Layout/Rendering Parameters/Standard Rendering Parameters data template.
  • Add fields to the parameters template data template
  • In the rendering or sublayout definition item, in the Editor Options section, in the Parameters Template field, select the parameters template created previously.
  • Go to the item where in the above rendering is being used, and insert values in parameter renderings fields. you can also have the default values set in parameter template’s standard values.

How to read the rendering parameters in code

Consider an example where we have added two fields TitleCss and DescriptionCss in parameter template and set some values in the corresponding renderings properties. Following code snippet will tell you how to read those values in code.

    string TitleCss = string.Empty, DescriptionCss = string.Empty;
    var rc = Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull;
    if (rc != null)
    {
        var parms = rc.Rendering.Parameters;
        TitleCss = parms["TitleCss"];
        DescriptionCss = parms["DescriptionCss"];
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s