Is there a way to pull in data from an external source using JS on each page in Webflow, while still maintaining a clean URL structure like "site.com/blog/my-blog-post" instead of using parameters like "site.com/blog?id=2"?

Published on
September 22, 2023

Yes, it is possible to pull data from an external source using JavaScript on each page in Webflow while maintaining a clean URL structure. Here's an approach you can follow:

  1. Create a collection in Webflow: Start by creating a collection in Webflow for your blog posts. This will allow you to add and manage blog posts within the Webflow CMS.

  2. Set up your clean URL structure: In Webflow, you can customize the URL structure for your collection items. Under the Collection settings, go to SEO settings and choose how you want the URLs to be generated. For instance, you can set it to "site.com/blog/my-blog-post".

  3. Add custom attributes: In the CMS Collection Item settings, create custom attributes to store the data you want to pull from the external source. For example, you can create an attribute called "external_data_url" to store the URL of the external data source.

  4. Write custom JavaScript code: In the Custom Code section of your site settings, add custom JavaScript code to fetch the data from the external source using fetch or similar methods. You can use the external_data_url attribute value to construct the URL for the API call. Make sure to handle the asynchronous nature of the call and update the content on your page accordingly.

  5. Display the data on each page: Using JavaScript, you can identify the specific element(s) on each page where you want to display the external data. Update the content of those elements with the data received from the external source.

By following these steps, you can pull data from an external source using JavaScript on each page in Webflow, while still maintaining a clean URL structure.

Additional Questions:

  1. How do I customize the URL structure for collection items in Webflow?
  2. Can I use JavaScript to fetch data from an external source in Webflow?
  3. What is the Webflow CMS and how can it be used in my projects?