Keyword

[SOLVED] Multi-select list: If certain value chosen do this

More
10 years 6 months ago #126477 by Tim
I am using a template override to show content depending on the output of certain extrafields. I'm trying to write an IF statement that shows a section of content only if the user has included a specific option from a multi-select list.

I can write IF statements if an extrafield equals or does not equal a value, but I can't work out how to say "show content IF list INCLUDES this specific value". The content needs to show whether they choose just that option in the list, or that option plus other options as well.

So far I have tried amongst other things:
Log in  or Create an account to join the conversation.

  • Mohamed Abdelaziz
  • Mohamed Abdelaziz's Avatar
  • Offline
  • Platinum Member
  • Joomla Developer
More
10 years 6 months ago #126478 by Mohamed Abdelaziz
Replied by Mohamed Abdelaziz on topic Re: Multi-select list: If certain value chosen do this
I think the second try should be like this:
<?php if(strpos($this->item->extraFields->ExtraField1->value , "Option1")): ?>
Show me!
<?php endif; ?>

Also, you use explode to get an array of the selected options, then use in_array to check for the existence of any option.

Multiple Extra Fields Groups for K2
AutoMeta for K2
Chained Fields for K2
More K2 Extensions In My Extensions Store

Please Log in or Create an account to join the conversation.

More
10 years 6 months ago #126479 by Tim
Thanks so much Mohamed - that works a dream! And I appreciate the pointer towards in_array too. May need to use that in the future too.

Please Log in or Create an account to join the conversation.