1

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;
        }
2
  • What if you have only 1 checkbox field to Rendering Parameter, does it behave the same? Oct 11 at 17:45
  • @GauravAgarwal There is another rendering paramater with two checkbox fields and it works well.
    – Qwerty
    Oct 11 at 18:14
0

I have faced a similar type of issue where I used checkbox in rendering parameter to create component flag based. I raised the ticket to the Sitecore Support portal and it's a bug in Sitecore version.

Sitecore suggested: As a workaround, please consider the parameter value as true if it is present and equals to 1.

Find below the Sitecore Support Response on the same:

Based on the provided information we would like to define the scope of the current case:

Issue definition: False value for bool rendering parameter is retrieved as null.

Investigation target: we will work diligently to help find the root cause and a resolution to the defined issue.

Additional notes:

  • if new circumstances are revealed during the course of the investigation, the scope can be changed based on the mutual agreement;
  • overall investigation course will be aligned with Sitecore general Scope Of Support: https://kb.sitecore.net/articles/463549;
  • questions that are not related to the investigation scope should be registered as separate cases: https://kb.sitecore.net/articles/004553.

Thank you for reporting the issue. I was able to reproduce it locally and registered a bug for the current Sitecore version. To track the future status of this bug report, please use reference number 502996.

More information about public reference numbers can be found here: https://support.sitecore.com/kb?id=kb_article_view&sysparm_article=KB0853187

As a workaround, please consider the parameter value as true if it is present and equals to 1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.