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

1webflow.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

1// Callback for subscription
2 const cmsCallback = async () => {
3 const page = await webflow.getCurrentPage()
4 console.log(await page.getPublishPath())
5 }
6
7// Subscribe to changes for CMS Pages
8 const unsubscribeCmsPages = webflow.subscribe('currentcmsitem', cmsCallback)