I want to connect a Gallery to several images in my collection, but as far as I can tell I can only connect a gallery to a single Collection column. True or false?
False. You can have a 1-many relationship between a row in a collection and pictures that belong to it. If I remember correctly, Tal gave some example code for it on this forum.
Hi Adam,
Here is an example of how it should look:
import wixData from 'wix-data';
let images = [];
$w.onReady(function () {
//TODO: write your page related code here...
getAllPictures();
});
async function getAllPictures() {
await getPicturesFromCollection('collection1');
await getPicturesFromCollection('collection2');
$w('#gallery1').items = images;
}
async function getPicturesFromCollection(collectionName) {
return wixData.query(`${collectionName}`)
.find()
.then((results) => {
results.items.forEach((item) => {
if (item.image) {
images.push({
src: `${item.image}`
});
};
});
});
};
Don’t forget to adapt to the names of your elements and database collection’s names.
Good luck!
Roi
Great! Thanks for your help!