Join the Webstudio community

Updated 2 months ago

.includes in expression editor?

At a glance

The community member is trying to display different content types (image, video, PDF) based on the file type. They are wondering if they can use the default "Show / Hide" with the expression editor or if they need to use custom JavaScript. The comments suggest that they can use string equality checks and the "or" operator in the expression editor to check for different file types. One community member mentions that the file type may return something like "image/webp" or "image/png", so they would need to check for that. Another community member suggests adding a simple string type to the data to make the checks easier. The community members provide examples of how to use the "or" operator in the expression editor, and one community member shares a link to the expression editor documentation.

Useful resources
I'm trying to show an image if the content type is an image, a video player if the content type is a player, show a pdf viewer if the file type is a pdf, etc. Can I use default "Show / Hide" with the expression editor? Or do I need to introduce custom JS embed?
O
S
12 comments
I mean you can't use .includes
but you can check the string equality
ah, just equality? I assume just = then?
The thing is that the the type returns image/webp, or image/png or image/jpeg

So ideally i can show if the string contains image, and not equal to specific..

If this is not possible, is "or" supported int the expression editor?

Then I can put in most common file extentions
add a type to the data that has a simple string, otherwise you have to check all 3
yes you can do or
a == 'x'|| a == 'Y'
also its a standard javascript expression, you can always ask AI
I see okay. I'm using directus as backend so i can't change too much of how its returned. I'll use the or. Sounds good. I tried ai and it gave me .includes. and couldnt get from the docs what's possible.

But thanks for the help!!! 🫶
Add a reply
Sign up and join the conversation on Discord