Using Sitecore 10.1
I have a rendering parameter with two fields - Checkbox
(Show Icon) & a Single-Line textbox
(Css Class).
The standard values for this rendering parameter template are set to checked & empty respectively.
When reading these values for a page rendering, if I uncheck Show Icon, the value is still "1".
But, if I uncheck Show Icon and add some value to Css Class, then value of checkbox is null (as expected).
Why is this behavior. Is the rendering parameter for checkbox reading from std. value if unchecked. If I uncheck the checkbox in the std. value, it is working as expected.
Could this be a bug in Sitecore?
Action method:
Mymodel model = new Mymodel(Sitecore.Context.Item)
{
ShowIcon = Utility.GetRenderingParameters(Templates.ContainerRenderingParams.ID, Templates.ContainerRenderingParams.Fields.ShowIcon) == "1",
CSSClass = Utility.GetRenderingParameters(Templates.ContainerRenderingParams.ID, Templates.ContainerRenderingParams.Fields.CssClass)
};
Helper method:
public static string GetRenderingParameters(ID renderingParametersTemplateID, ID renderingParametersTemplateFieldID)
{
string parametersTemplateFieldNameInRendering = "Parameters Template";
string renderingParameters = string.Empty;
Rendering currentRendering = RenderingContext.Current.Rendering;
if (currentRendering != null)
{
Item currentRenderingItem = GetItem(System.Convert.ToString(currentRendering.RenderingItem.ID));
Template template = TemplateManager.GetTemplate(renderingParametersTemplateID, Context.Database);
TemplateField templateField = template.GetFields(true).Where(x => x.ID == renderingParametersTemplateFieldID).FirstOrDefault();
renderingParameters = templateField != null ? currentRendering.Parameters[templateField.Name] : string.Empty;
}
return renderingParameters;
}