december 16, 2011
Understand the challenge that is Sitecore parameter templates with this first in a series of posts. First up- making your sublayout configuration more intuitive.
Sitecore's sublayouts and Page Editor interface offer some out-of-the-box configuration options which allow content authors to alter the behaviour of their content. One example is the "data source" property which is often leveraged by Sitecore developers to alter what content item drives the sublayout behaviour.
Developers who have worked with the "additional parameters" property may have found how difficult it is to get a content author to enter in the correct configurations for a sublayout in a querystring-like format.
Along come parameter templates!
1. Create the template
Like any standard data template that would be created in Sitecore, you start by creating a new template and extending an existing Sitecore template: Standard Rendering Parameters.
FULL PATH: /System/Layout/Rendering Parameters/Standard Rendering Parameters
2. Create the parameters
Create fields on the template using sitecore field types that will help the content author provide selections or data (checkboxes, droptrees, etc.).
3. Tie to the sublayout
Attach the template to your sublayout using the Parameters Template field on your sublayout item.
4. Configure through Page Editor
Using Page Editor, you can access the properties of the sublayout on the page and change parameters using the new fields you've provided via the template.
As a developer, you can access these parameters in exactly the same way you are accustomed to when accessing the "Additional Parameters" values:
Sublayout sublayout = Parent as Sublayout;
NameValueCollection sublayoutParameters = Sitecore.Web.WebUtil.
string selectedItemsValue = sublayoutParameters["Selected Items"];
The only difference is now your content authors will have a better experience entering the configurations, and you will have fewer headaches trying to validate the parameter values that are entered!