.contains question... is this possible?
So I'm trying to see if a variable contains more than one string. Here's what I have right now...
#if ($keywords.contains("Alpha")
This text displays.
#end
Thing is, I have multiple keywords per page. I'd like to see if "keywords" contains multiple words, and if so return the results that have either keyword.
This doesn't work, but am I close to something possible?
#if ($keywords.contains("Alpha" or "Bravo" or "Charlie")
This text displays.
#end
Any ideas?
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Ryan Griffith on Aug 20, 2015 @ 11:34 AM
Hi John,
There are a few ways you could go about this, but the best option will depend on how things are set up.
When you have a moment, can you describe what your
$keywords
variable looks like and how you are planning to defining those multiple words? For instance, is$keywords
a comma separated list coming from a metadata field? Are the multiple words coming from a select box set to multiple, or multiple checkboxes?Thanks!
2 Posted by Wing Ming Chan on Aug 20, 2015 @ 12:05 PM
Hi John,
What
WingString.contains
cares about is any substring. So the substring can be anything, not just words. To create a disjunction, you can useor
between boolean expressions. For example:3 Posted by Ryan Griffith on Aug 20, 2015 @ 01:37 PM
Thank you for following up, Wing.
What I was getting at is if the words to check is an array, he may be better off building a RegEx expression:
Ryan Griffith closed this discussion on Aug 27, 2015 @ 08:21 PM.