Adding Blog Comments to Webflow using Xano!
Ever wanted to add a comment section to your blog but found it challenging to implement? Well, with Xano and Webflow, you can easily add this functionality without writing a single line of code! In this step-by-step guide, we'll show you how to integrate a comment section into your Webflow-built blog, allowing your readers to leave comments and engage with your content seamlessly.
What is Xano?
Xano is a no-code platform that enables you to build and deploy backend services for web and mobile applications without writing code. It provides a visual interface for designing data models, creating APIs, and setting up authentication and authorization. Xano aims to simplify the process of backend development, making it accessible to both non-technical users and developers who want to speed up their development process.
Prerequisites
Before we begin, make sure you have:
- A Xano account (you can sign up for a free trial if you haven't already)
- A Webflow project with a blog set up using the Webflow CMS
Step 1: Set up the Data Structure in Xano
- In your Xano account, create two tables:
BlogPostsandComments. - In the
BlogPoststable, add the following fields:
slug(Text field) - This will store the unique identifier for each blog post.commentIds(Table Reference field formatted as a List) - This will store the IDs of comments associated with each blog post.
- In the
Commentstable, add the following fields:
author(Text field) - This will store the name of the comment author.comment(Text field) - This will store the comment text.
Step 2: Create APIs in Xano
- Create a
POSTAPI endpoint calledpostCommentto handle new comment submissions. This endpoint should:
- Accept
author,comment, andslugas input parameters. - Check if a record exists in the
BlogPoststable for the providedslug. - If a record exists, update the
commentIdsfield by appending the new comment ID. - If no record exists, create a new record in the
BlogPoststable with the providedslugand the new comment ID. - Create a new record in the
Commentstable with the providedauthorandcomment.
- Create a
GETAPI endpoint calledgetCommentsto retrieve comments for a specific blog post. This endpoint should:
- Accept
slugas an input parameter. - Query the
BlogPoststable for the record with the providedslug. - Retrieve the
commentIdsassociated with the found record. - Query the
Commentstable to retrieve the comments with the retrievedcommentIds. - Format the comment timestamps to a more readable format (e.g., day, month, year).
Step 3: Set up the Comment Section in Webflow
- In your Webflow project, navigate to the blog post template page.
- Add a new section below the blog post content and insert a form block. This form will be used for comment submission.
- Change the name field ID to
author. - Change the label of the second field to
comment. - Change the submit button type to
post. - Set the submit button action to the
postCommentendpoint URL from Xano (copy the endpoint link from Xano and paste it here).
- Add another section below the form and insert a grid block. Give this grid an ID of
gridComments. - Inside the grid, add a div block with the class
sampleStyle. This will act as a template for rendering individual comments.
- Inside the
sampleStylediv, add a paragraph element for the comment text. - Add another div block inside the
sampleStylediv. - Inside the nested div, add a heading 3 element for the author name.
- Add a heading 5 element for the comment date.
- Hide the
sampleStylediv so it doesn't show up on the page (we only need it as a reference for the custom code).
Step 4: Add Custom Code to Webflow
- In the page settings of your blog post template, go to the "Custom Code" section and paste the provided JavaScript code from the Xano resources (linked in the video description).
- Update the
XanoURLvariable at the top of the code with thegetCommentsendpoint URL from Xano (copy the endpoint link from Xano and paste it here). - Save the changes.
Step 5: Test and Deploy
- Publish your Webflow project and open the blog post page.
- Try submitting a new comment using the form.
- Verify that the new comment appears on the page without a page refresh.
- Check the
CommentsandBlogPoststables in Xano to ensure the data is being stored correctly.
Congratulations! You've successfully added a comment section to your Webflow-built blog using Xano's no-code backend solution. Your readers can now engage with your content by leaving comments, and you can manage the comments directly in Xano.
This approach can be easily adapted to handle other use cases like product reviews or any scenario where you want users to submit form data and have it appear on the page without a page refresh.
Sign up for Xano.
100,000+ people build on Xano.
Start today and scale to millions.