top of page
atlan logo green.png

Start a project

Start a project

Selected work
Display Rich Content using Wix Dynamic Page with Database Connection - Velo

Practical guides on Wix Studio, Velo, Squarespace, e-commerce and SEO — written from real client projects.

​

​
Share Post

Keep reading

Journal

Display Rich Content using Wix Dynamic Page with Database Connection - Velo

Writer: Atlan Design
Atlan Design
Jan 1, 2024
1 min read

Updated: Sep 19


Wix dynamic page displaying rich content from a CMS collection

// API Reference: https://www.wix.com/velo/reference/api-overview/introduction
// “Hello, World!” Example: https://learn-code.wix.com/en/article/1-hello-world

import wixData from 'wix-data';

$w.onReady(function () {

    $w("#dynamicDataset").onReady(async () => {
        
        pageLoader();

        $w("#ppbutton").onClick(async (events) => {
            $w("#dynamicDataset").setFilter(wixData.filter().contains("legalType", "PP").eq("isActive", true)).then(() => {
            pageLoader();
            });
        })

        $w("#tcbutton").onClick(async (events) => {
            $w("#dynamicDataset").setFilter(wixData.filter().contains("legalType", "TC").eq("isActive", true)).then(() => {
            pageLoader();
            });
        })

    })
});

function buttonSwitch(legalType) {
    if (legalType == "PP") {
        $w("#ppbutton").disable();
        $w("#tcbutton").enable();
    } else if (legalType == "TC") {
        $w("#tcbutton").disable();
        $w("#ppbutton").enable();
    }
}

async function pageLoader() {
    let item = await $w("#dynamicDataset").getCurrentItem(),
        updatedDate = new Date(item._updatedDate),
        createdDate = new Date(item._createdDate);
        buttonSwitch(item.legalType);

    $w("#date").text = "Last Updated: ";

    if (updatedDate === createdDate) {
        $w("#date").text = $w("#date").text + " " + createdDate.toLocaleDateString('en-US', { 'month': 'long', 'year': 'numeric' });
    } else {
        $w("#date").text = $w("#date").text + " " + updatedDate.toLocaleDateString('en-US', { 'month': 'long', 'year': 'numeric' });
    }

    $w("#content").expand();
    $w("#date").show();
}

Have Fun!

Comments


bottom of page