How to hide/show a strip based on database entries?

Hi there,

There are a lot of posts/threads about this topic, please observe the forum for similar questions before posting new ones.

First of all, you need to wait until you get the item you want to evaluate from the database or the dataset, this might sound obvious, but I’m sure a lot of people don’t see it this way.

Database Scenario

import wixData from 'wix-data';

$w.onReady(() => {
    return wixData.query('collection')eq('field_name', value).find().then(x => {
        const item = x.items[0];
        
        // Run the evaluation here
    })
})

Dataset Scenario

$w.onReady(() => {
    $w('#dataset').onReady(() => {
        const item = $w('#dataset').getCurrentItem();
        
        // Run the evaluation here
    })
})

Now that we have the item that we need to evaluate, we can use a simple if statement to check any field

// Example 1: Check a boolean value
if (item.premium) {
    // Show premium content
    $w('#premiumStrip').show();
} else {
    // Show regular content
    $w('#regularContent').show();
}


// Examlpe 2: Show exclusive content for those with 10+ score
if (item.score >= 10) {
    // Show exclusive content    
} else {
    // Show a message
    $w('#message').text = 'You need higher score to get access...';
}

Hope this helps~!
Ahmad