APIsChangelog
Log In
APIs

User changes CMS Page

webflow.subscribe("currentcmsitem", callback)

Use this method to listen for specific events in your app. When a user selects a collection page or chooses a new CMS item on a collection page, this event will trigger. This can be especially useful for determining the path of auto-generated pages from a CMS or Ecommerce collection.

Syntax

webflow.subscribe( event: 'currentcmsitem',callback: (element: null | AnyElement) => void): Unsubscribe;

Parameters

event : "currentpage"

The name of the event to subscribe to.


callback: (() => void)

The callback function to execute when the event occurs.


Returns

Unsubscribe

This is a special function returned after subscribing. Call this function when you want to stop listening to the event and discontinue receiving notifications.

Example


// Callback for subscription
    const cmsCallback = async () => {
      const page = await webflow.getCurrentPage()
      console.log(await page.getPublishPath())
    }

// Subscribe to changes for CMS Pages
 const unsubscribeCmsPages = webflow.subscribe('currentcmsitem', cmsCallback)