Join the Webstudio community

Updated 2 months ago

Possible to slice array?

At a glance
Hi, I‘m new to Webstudio and I hope I‘m asking this in the right place :)

I’m using Google Sheets as a CMS with linked images from Google Drive and with the table turned into a JSON via Google Apps Script. So this is about loading data dynamically.

It works well to bind components to single data points (like things.data[2].image) as well as loading all the data dynamically into a Collection, it all displays correctly.

Now my issue is that in some places of my website I only want some parts of my data, for example [0] to [50] are of the category „great fruit“ while [51] to [100] is „great cakes“ (the namings are just examples).

I tried things like „things.data[0-50]“ and „things.data.slice(0,51);“ but I start feeling that maybe this isn’t possible?

Can I only load part of my JSON into a Collection? By for example filtering it somehow or specifying with an if-clause, because I do have categories in my table by which I could filter but I don’t really know where to put any of that or how.

I‘m trying to make galleries that follow certain categories with that. I could create different tables per category, but I‘d rather find a better solution in case there is one.

Thanks for any tip!
B
S
S
4 comments
Hi. Currently expression is very limited to js operators. Calling functions is not allowed for security reasons.

One option to filter is using collection with whole data but rendering with "Show" setting on collection item.
So for example if you have a column with cetegory jist write this in item show setting CollectionItem.category === "great fruit"
Cool, thank you for your help! That should solve the issue 😎 I’ll try it later
I have been trying to figure this out for weeks now and I finally joined the discord to search for help. Thank you so so much this is a live saver
Add a reply
Sign up and join the conversation on Discord