官术网_书友最值得收藏!

Creating strongly typed rendering parameters

In the previous recipe, you learned using additional parameters, but these are loosely typed. So, chances are that content authors may enter invalid values such as non-numeric values for the RecordsCount parameter and a style class in CssClass that does not exist, and so on, which can lead to misbehavior of the application. Now, just imagine how happier your content authors will be if they see strongly typed parameters such as checkbox, integer, droplist, and so on.

In this recipe, we will use the Integer field for RecordsCount and a Droplist field for CssClass so that we always get valid values from the input.

Getting ready

Create a Stylesheet Class template and create different items outside the Home item, as shown in the following image. We will use the CssClasses folder as a source of the droplist field.

Getting ready

How to do it…

We will first create a template with the required input parameters as its fields:

  1. Create a List Rendering Parameters template, set /sitecore/templates/System/Layout/Rendering Parameters/Standard Rendering Parameters as its base template, and create the required fields as follows:
    How to do it…
  2. Select the Simple List view rendering that we created in the previous recipe. In its Parameters Template field, select the parameter template that we just created:
    How to do it…
  3. Now, select the component from either the Experience Editor or Content Editor, and open component properties. You will find strongly typed parameters that we just created, as shown in the following image:
    How to do it…
  4. Remove these additional parameters from component properties. Additionally, if you have changed the parameters' names here, then make sure that you update in the ItemList model too.
  5. Preview the page; you will see how your own parameters are working.

Note

You can use any Sitecore field type for strongly typed rendering parameters.

主站蜘蛛池模板: 资兴市| 赤城县| 连城县| 玉树县| 金平| 永和县| 汝州市| 冕宁县| 东丽区| 黎城县| 阜新市| 泰顺县| 卢湾区| 大连市| 伊金霍洛旗| 阳东县| 娄底市| 巴中市| 水富县| 高州市| 响水县| 卢龙县| 德昌县| 岢岚县| 固阳县| 岳池县| 闵行区| 荃湾区| 玛沁县| 齐齐哈尔市| 岐山县| 获嘉县| 高州市| 昌都县| 垣曲县| 胶南市| 陆河县| 安西县| 普兰店市| 金堂县| 罗甸县|