**Question:**How to resolve the error: Cannot assign to ‘slides’ because it is a read-only property. Product:
Wix Studio Slidershow Repeater
What are you trying to achieve:
Trying to display different slides based on the whether the current minute is odd or even
What have you already tried:
VELO Code:
import wixData from 'wix-data';
$w.onReady(function () {
// Get the current minute of the day
const currentMinute = new Date().getMinutes();
// Determine if the minute is even or odd
const isEvenMinute = currentMinute % 2 === 0;
// Get the current displayWeek based on whether the minute is even or odd
const displayWeek = isEvenMinute ? "Even" : "Odd";
// Query the CMS collection based on the determined displayWeek value
wixData.query("HomePageSlideShow")
.eq("displayWeek", displayWeek)
.limit(10) // Limit to 10 images
.find()
.then((results) => {
// Extract the image URLs from the filtered results
const images = results.items.map(item => item.image);
// Update the slides property of the Wix Studio Slide Repeater
$w("#slideshow2").slides = images.map(imageUrl => ({src: imageUrl}));
})
.catch((error) => {
console.error("Error: " + error);
});
});
The slides property is read only so it can’t be set. Would need to do something else like defining all slides in the UI and then calling changeSlide() to go to the correct slide(s) to display.
I don’t that would automatically select which slides to show based on the time of day. The field in the dataset, display week, is populated with of and even numbers associated to each slide image. Using WixStufio does not allow to set a condition, I believe.
My purpose is display new slides based on whether hour or minute or day of week is odd or even, thus giving the end user the appearance the web is being updated regularly.
A filter will give you the same result as a query, the difference is the filter is applied to the dataset so only the matching results appear on the page . While a query forces you to assign the results via code (which a slideshow repeater does not allow you to do).
I have a randomized content tutorial that may help you better understand the concept……
Defining all slides. As in putting all slides in the Slideshow Repeater element in the editor and then programmatically choosing which to display based on some custom logic.
It appears that filtering the CMS dataset does not work for wixstuio slideshow repeater. According to the documentation the Slideshow repeater filter does not use the CMS filter but must be done manually in the Slideshow repeater. Hence, I have not found a way to filter the slideshow repter element through code so far.