1. Developer guides

Query the page context

Version: 0.4
Before you begin
  • Complete the SDK quick start.

    In the quick start, you make your first query by running client.query("application.context").

If your app uses any of the SitecoreAI Page builder extension points, you can query the page context to retrieve details about the current page and site.

To query the page context:

  1. In the SDK initialization code where you run the useMarketplaceClient hook, in the Effect Hook, below the "application.context" query, create a new query, then save your changes:

    // Make a query to retrieve the page context
    client.query("pages.context")
      .then((res) => {
        console.log("Success retrieving pages.context:", res.data);
      })
      .catch((error) => {
        console.error("Error retrieving pages.context:", error);
      });
  2. In the SitecoreAI Page builder, open your web browser's console, refresh the page, then open your Marketplace app.

  3. In the console, find the log for Success retrieving pages.context and inspect the object. The object contains all the details about the current page and site.

This query also lets you subscribe to page events.

If you have suggestions for improving this article, let us know!