Related Items repeater on dynamic page

I am trying to add a repeater of related items to a dynamic page. The related items will be determined by matching a reference field - “category” connecting to my categories database.

The basic filter code works perfectly, but the underlined lines below break the code.

How do I get the current page’s “category” value and match it to the database to filter the repeater?

//related repeater
$w(“#eventsDataset”).onReady( () => {
let category = $w(“eventsDataset”).getCurrentItem(“category”);
let d = new Date(); // get today’s date
.include(“venue”, “categories”)
.ge(“date”, d)
.eq(“approved”, true )
.eq(“category”, category)
.then((results) => {
$w(“#relatedRepeater”).data = results.items;

Hi Stacey,

When using getCurrentItem() you don’t need to pass any value, instead, the function returns an object with the field keys as its properties.
So instead of using this:

 let category = $w("eventsDataset").getCurrentItem("category"); 

Use this:

 let category = $w("eventsDataset").getCurrentItem().category; 

Now, category will be an ID of the reference field in your “events” collection and

 .eq("category", category) 

Should work.

Also, I would recommend giving your items and variables meaningful and unique names so you won’t get confused what ‘category’(variable, field key, collection name) you are referring to.

Best of Luck!

  • Lior

Thanks! This is getting much closer!
Instead of filtering the repeater items to match the category of the current dynamic page, the items are filtered to match the category “music” (the first value in the categories database) on every dynamic page, regardless of what the dynamic page’s true category is.

I tried pulling the current dynamic page’s category from the dynamicDataset instead of eventsDataset (just changing the line below), but then the repeater returns no results at all.
let category = $w(“dynamicDataset”).getCurrentItem().category;

Any tips on why this could be? I’m at a loss!

Hi I am having the same problem. I am confused with the sample codes above as they are all named “category”.

Basically I want to achieve the same thing, a related workshops repeater in a dynamic page.

I have
One data collection named “Workshops”
My on-page dataset is named “#dynamicDataset
My matching reference field is called “sorting”
And I need an additional function where the “repeater” will be hidden if theres no other related items.

Can anyone help me with the code? Thank you in advance.

This is my current code which is not working

import wixData from 'wix-data';

$w("#dynamicDataset").onReady( () => {
let sorting = $w("#dynamicDataset").getCurrentItem().sorting; 
    .include("sorting", "Workshops")
        .eq("available", true)
       .eq("sorting", sorting)
        .then((results) => {
            $w("#repeater").data = results.items;

1 Like