How to show an image in single repeater item if certain Selection Tag is present? #repeater #ifstatement #forEachItem #selectiontag

Greetings Fellow Wixers,

I hope all is well

Question: I have a REPEATER connected to my ‘CreatedPolls’ DATASET. My dataset contains selection tags of different video game systems. I want to use an IF STATEMENT that simply SHOWS a console image on the repeater if that selection tag is present in the item for it. My code is not working well, it either SHOWS or HIDES the image for ALL the repeaters instead of the individual one . What am I doing wrong?

[CreatedPolls Collection]

[Repeater Connected to Dataset] (This may be the issue, the hidden images isn’t directly connected to the system tags) ???

[PublishedPage] (XBOX icon shows on ALL repeaters instead of JUST the ones where the XBOX tag is present in the item) :frowning:


$w . onReady ( () =>
{
//Check if Member is Logged in
const isLoggedIn = authentication . loggedIn ();

//If logged in Get Current Member 
if  ( isLoggedIn ) 
{ 
    isloggedIn (); 
} 
**else** 
{ 
    notloggedIn (); 
} 

//Showcase Number of Polls Created by Community/When DATASET is Ready 
**$w** **(** **"#createdPolls"** **).** **onReady** **( () =>** 

{
let count = $w ( #createdPolls ). getTotalCount ();
$w ( #totalPolls ). text = count . toString ();

    **//Get each repeater item tags and show the icons based on the tags** 
    **$w** **(** **"#pollRepeater"** **).** **forEachItem** **((** **$item** **,** **itemData** **,** **index** **) =>** 

{

        let  **title** **=** **itemData.title** **;** 
        const  **systemTags** **=** **itemData.gameSystems** **;** 
        **console** **.** **log** **(** **"Current index and title is: "** **,** **title** **,** **index** **);** 
    
        if **(** **systemTags** **.** **includes** **(** **"xbox"** **) ===** **true** **)** 

{
$w ( #xboxIcon ). show ();
}
else
{
$w ( #xboxIcon ). show ();
}

    }) 

}) 

});


Any help would be greatly appreciated.

Happy New Years :slight_smile:

Alvin Wallace
[Skreen]

Hello Alvin,

Repeaters will use $item instead of $w.

Try this:
$w . onReady (() => {
//Check if Member is Logged in
const isLoggedIn = authentication . loggedIn ();

//If logged in Get Current Member 
if  ( isLoggedIn ) { 
    isloggedIn (); 
} 
else  { 
    notloggedIn (); 
} 

//Showcase Number of Polls Created by Community/When DATASET is Ready 
$w ( "#createdPolls" ). onReady (()  =>  { 
    let  count  =  $w ( "#createdPolls" ). getTotalCount (); 
    $item ( "#totalPolls" ). text  =  count . toString (); //($item if in repeater, if not use $w) 

    //Get each repeater item tags and show the icons based on the tags 
    $w ( "#pollRepeater" ). onItemReady (( $item ,  itemData ,  index )  =>  { 

        //if item data is xbox 
        if  ( itemData.gameSystems . includes ( 'xbox' )) { 
            $item ( "#xboxIcon" ). show () 
        } 
        
        //if item data is not xbox 
        if  ( ! itemData.gameSystems . includes ( 'xbox' )) { 
            $item ( "#xboxIcon" ). hide () 
        } 
        
        //you can use if else but if you have multiple statements, the code will read better as listed above. 
        //sometimes it will always run else and your code will not run the way you like  

        //consider ternary operator -- short version of if/else 
        itemData.gameSystems . includes ( 'xbox' )  ?  $item ( "#xboxIcon" ). show ()  :  $item ( "#xboxIcon" ). hide () 
    }) 

}) 

});

@oakstreetassociates

Oh my goodness. I was literally up until ~11pm last night pulling my hair out trying to solve this and you solve it for me in a few minutes. Thank you sooo much!! You have no idea how much you just helped me out and educated me.

On one of my site’s pages (Contact Us) I have a ‘EndScreen’ credit that simply gives shout outs to everyone that’s helped me on my project. I’m adding your team on there.

Thank you soo much :slight_smile:

Alvin