Retrieve dynamic page text element value - (currently returning default value)

I have a text element on a dynamic page that is displaying the value of a text field in one of my collections. In this example it shows “Easter”

I am querying with this text value using .eq but instead of the value being “Easter” it shows as “title” which is its default text value.

I understand the default value for my text element is being retrieved BEFORE the dynamic page content is populated and I know this can be fixed with setTimeout() but is there another, more secure way?

I currently have my code in an onReady function

	 const collectionTitle = $w("#title").text;

  // Query the "Songs" collection based on collectionTitle
    .eq("collection", collectionTitle)
    .then(results => {
      // Check if there are results
      if (results.items.length > 0) {
        // Show the "listRepeater" and hide the "errorMessage"
        $w("#listRepeater").data = results.items;
      } else {
        // Show the "errorMessage" and hide the "listRepeater"

Any help is appreciated!

If it is a dynamic page, you can query a dataset instead of querying the CMS to fetch the data before page loads, so that the default text won’t show up.

1 Like

Of course! That did the trick - thank you so much. :+1: