Inserting value from the CMS field into custom code

I have several store locations where each location has its google reviews.

I have implemented a code I found online which lets me pull reviews from Google places and display 5 of them on a page. However, the code uses a static, hard-coded ID of the store location.

Click here to see it.

I need to make this solution dynamic by using CMS template and place IDs sourced from the CMS item.

I have placed the script in the stores’ template page, and now I need the location ID to be pulled from the store CMS field and placed into the script.

You can take a look at the code located in the Saloni Template
The Place ID code is located in the field named Place ID

Here is my site Read-Only

While at it, maybe you can tell me why I can only get 5 of them. I don’t see any parameters in the script indicating this value. Is this set up elsewhere?

Thank you very much

1 Like

@memetican, maybe you have time to look at this one for me as well. Thank you very much.

@Roadhat - would this not work?

image

When you say you are limited to 5 what do you mean?

1 Like

As Sam showed, in a CMS Collection page, you can insert variables into your page custom code as well, just like you can in an HTML Embed. It’s the + Add Field link in the top right corner.

image

Make sure to put "quotes" around your value, it won’t be quoted automatically.

Limited to 5… I don’t see anything in the script itself, you’ll want to check the google APIs docs for that call and see if there is a way to specify that you want more.

For what it’s worth, if you use Zapier or Make, you might prefer to use automation to collect your reviews into the CMS, and then serve them from there. That way you can use Webflow’s built in Collection Lists and databinding rather than minting HTML in your script. It also lets you do thing like sort the best ones at the top, filter out any low ratings, randomize the sort, etc.

2 Likes

Thank you so much @sam-g and @memetican !
This is amazing hos simple the solution was :slight_smile: yet I was nowhere close to a solution on my own since I don’t know JS syntax and had no idea one can use tags there as well. Yet, using copy-paste and some logic, I manage to get places with it. However, in situations like this, I depend on your help. So I am very thankful you are taking time to do this.

Thank you both again!

@sam-g by limited to 5 I meant it pulls only 5 reviews although there are many more.

@memetican this approach is a short-term solution for meeting the deadline. I plan to do as you suggested. On top of the benefits you mentioned, I am not sure how Google looks on what I am doing.
I have tried using Zappier on two occasions with products and have run into issues. Maybe I should start with something less complicated like this list :slight_smile:

My next challenges are finding why the reviews all showing in English if they were natively written in Croatian, and why only 5 of reviews are being pulled.

How do I pull field from other collections into the code? The + Add Field only gives me fields from the current collection.

Hi @Chang_Chen welcome to the community!

To do this you’d need to pull those collections and their fields in via a Reference Field - Webflow University

There are two types single and multi ref.

Hello Sam,
can you help me to update the price based on quantity. my price catalog is 1-5 (65,60,55,50,47) is different after that they can select any amount max 80. I can set the min and max value but i cant do the price dynamically.

Hello memetican
can you help me to update the price based on quantity. my price catalog is 1-5 (65,60,55,50,47) is different after that they can select any amount max 80. I can set the min and max value but i cant do the price dynamically.

Hi Shihab, I generally only do programming as part of my client work, because there are a lot of communications and considerations to be taken for each client. If you’re looking for some professional help, you can drop me a message.

For something simple though, I recommend you use custom attributes on your elements and then use ChatGPT with a clear description of what you’re doing, what custom elements to look for, what values to get, it can be quite good at writing simple formulas. You can also paste in some of the HTML you’re using.

It’s a great learning tool and can help you shape simple solutions quickly.