Welcome back! In this tutorial, we'll continue our exploration of the powerful integration between Webflow, Memberstack, and Xano. If you haven't already, I highly recommend watching Part 1 where we covered setting up the foundation and listing items based on membership.
Now, let's take it a step further by creating a single item view, allowing users to favorite items and add comments. Buckle up, because we're about to unlock some really cool functionality!
First, let's create a new page in Webflow called "item". This will be the destination when a user clicks on an individual item from the list view.
javascript
// Get the item ID from the URL
let myURL = new URL(window.location.href);
let id = myURL.searchParams.get("id") || "1";
// API endpoint to fetch a single item
const itemUrl = "https://YOUR_XANO_API_ENDPOINT/items/" + id;
// Function to fetch and display the item
function getItem() {
const xhr = new XMLHttpRequest();
xhr.open("GET", itemUrl);
xhr.onload = function () {
if (xhr.status === 200) {
const data = JSON.parse(xhr.responseText);
const itemContainer = document.getElementById("itemContainer");
const card = itemContainer.getElementsByClassName("sample-card")[0];
card.getElementsByTagName("img")[0].src = data.banner;
card.getElementsByTagName("h3")[0].textContent = data.name;
card.getElementsByTagName("p")[0].textContent = data.description;
}
};
xhr.send();
}
// Call the getItem function after a short delay
setTimeout(getItem, 250);
This JavaScript fetches the item details from the Xano API based on the item ID in the URL. It then populates the sample card with the item's banner image, name, and description.
Now, let's enable users to favorite items. We'll create a "Mark as Favorite" button that submits a form to Xano, storing the favorited item.
html
<input type="hidden" name="itemId" data-name="Item ID" value="{{item.id}}">
<input type="hidden" name="formType" data-name="Form Type" value="favorite">
<input type="hidden" name="webflowMemberId" data-name="Webflow Member ID" value="{% static_member_info 'id' %}">
Finally, let's allow users to leave comments on items. We'll create a comment form and display existing comments from Xano.
Congratulations! You've successfully created a single item view with favoriting and commenting functionality, seamlessly integrating Webflow, Memberstack, and Xano. This powerful combination unlocks endless possibilities for building dynamic and feature-rich web applications without writing a single line of code.
This transcript was AI generated to allow users to quickly answer technical questions about Xano.
I found it helpful
I need more support