0

I have a view that works fine to display rendering parameters for a title and body of a widget, however, I've added a checkbox field to the rendering items for that template and when I try to use it in the view to check it seems to give me a null reference exception.

I've tried checking to see if RenderingContext.Current.Rendering.Parameters["Expandable"] is equal to "0" or "false" but this fails regardless of whether the checkbox is checked or not and when I try to display RenderingContext.Current.Rendering.Parameters["Expandable"] as part of the body of the widget it throws a null reference exception.

What am I doing wrong?

How do I retrieve the value of such a rendering parameter within the view?

2
  • 1
    First thing I would look at is the raw value of the rendering parameters. You can do this by enabling the raw value checkbox in the View tab and then looking at the display properties of the rendering. Make sure what is in there is what you expect. Next make sure that everything is published :)
    – Gravypower
    Commented Feb 4, 2019 at 22:20
  • @Gravypower, Thanks, I ended up changing it to a droplist as the item got expanded to cover more than just expaneded or contracted. The droplist value comes through as a string without issue, so at least for now I don't have to deal with this, but will look at raw values if I have to deal with a checkbox parameter again... Commented Feb 6, 2019 at 19:17

2 Answers 2

4

Just ran across this myself. If it's set to "checked", the parm has a value of "1". If it's set to "unchecked", the parm doesn't exist at all. (This behavior is on Sitecore 8.0)

1
  • 1
    Precisely. The correct way is to check it for true, then assume false otherwise. And that is done by testing for "1", whether it is in a checkbox field value or - as here - as a rendering parameter.
    – Mark Cassidy
    Commented Feb 28, 2019 at 16:55
0

Verify if you have inherited "Standard Rendering Parameter" for your rendering parameters template. Sitecore won't be able to detect the fields as rendering parameters otherwise.

1
  • I'm not sure where to look for this inheritance. It's not listed for the rendering that I'm including in the presentation details, which contain the parameters. The thing is, though, that the other rendering parameters are showing up just fine, it's just the checkbox that isn't. I added the checkbox field to the parameters template, saved and republished it but it doesn't seem to be available in the view somehow... Commented Feb 5, 2019 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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