1

I have a checklist with value(a,b,c,d) in the items.

In the rendering variant template how can I check If 'a' is checked? I am using Sitecore 9.2

2
  • Could you please add more details regarding where you are trying to verify the checked item and how are you displaying the checklist? Mar 8, 2021 at 8:20
  • I have a rendering variant for search result component. Inside that rendering variant I have template and inside that I am trying to fetch the checked items like $item.Fields.Fieldaname.Its working for checkbox field but not with Checklist filed Mar 8, 2021 at 8:24

1 Answer 1

1

Note that NVelocity is removed in version 9.3 so if you have other options you might want to use those.

But to answer your question, you could do something like this:

#set ($checks = $item.Fields.get_Item("YourCheckListField").ToString)
#if ($checks.contains("THE-GUID-OF-THE-ITEM-A"))
... do your stuff
#end

This gets the value from the field, which will be the raw value so the '|' delimited string of guids (in capitals). You can check if the guid of your "A" item is in there.

5
  • I tested like #set ($checks = $item.Fields.get_Item("Zoning").ToString()) $checks it came always $checks instead of value Mar 8, 2021 at 9:48
  • Can you edit the question with what you are doing? I tested the code above in a 9.2 and that works.
    – Gatogordo
    Mar 8, 2021 at 9:57
  • Due to secure N/w I am unable to share the details.Can u pls share the field info if possible? Mar 8, 2021 at 10:01
  • Thanks .It worked I was providing wrong Field type.Thanks a ton Mar 8, 2021 at 10:06
  • Ok - don't forget to mark the answer as accepted if it solved your issue ;)
    – Gatogordo
    Mar 8, 2021 at 14:55

Your Answer

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

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