#dynamic-page #wix-location
Page through the dynamic pages using a
Next button. When there are no more pages, go back to the beginning. This works the same for the
Previous button. When there are no more previous pages, go to the last page.
Go to the Dynamic Page Loop example page.
See more examples at Gramp’s Workbench .
3 Likes
Hi, thank you so much for the template.
I’ve tried doing the same with my website but I’m a bit confused.
To create my dynamic pages’ URL I use 2 fields, Order (numbers) and URL Text (text field)
I tried replacing some tags in your code to match mine but I can’t make it work for some reason.
I’m not an expert with code as you can imagine
This is the code I’m using
import wixLocation from 'wix-location';
$w.onReady(function () {
$w("#dataset1").onReady(() => {
const numberOfItems = $w("#dataset1").getTotalCount();
$w("#dataset1").getItems(0, numberOfItems)
.then( (result) => {
const dynamicPageURLs = result.items.map(item => item['order']);
} )
.catch( (err) => {
console.log(err.code, err.message);
} );
} );
});
export async function btnPrev_click(event) {
let res = await $w("#dynamicDataset").getPreviousDynamicPage();
if(res !== null) {
wixLocation.to(res);
} else {
let count = $w("#dataset1").getTotalCount();
await $w('#dataset1').setCurrentItemIndex(count);
let item = await $w('#dataset1').getCurrentItem();
let country = item.order;
country = country.replace(/ /g, '-');
wixLocation.to('/parks-project/' + country);
}
}
export async function btnNext_click(event) {
let res = await $w("#dynamicDataset").getNextDynamicPage();
if(res !== null) {
wixLocation.to(res);
} else {
await $w('#dataset1').setCurrentItemIndex(0);
let item = await $w('#dataset1').getCurrentItem();
let country = item.order;
country = country.replace(/ /g, '-');
wixLocation.to('/parks-project/' + country);
}
}
Any help is much appreciated!
Thank you
Realize that it is very difficult to read code that is not properly formatted and indented.
What isn’t working? You need to provide more information in order for us to be able to assist.