Replace certain area of running text with text from field in a particular item, in a particular collection.

Hi there!

As the title says, I’m looking to write some code that checks a certain collection that stores what certain fees are for registration, and then replaces a certain word or part of a text element I have in a terms and conditions sort of section.

This way, when the fees change, it automatically updates anywhere on the site that I put this information (I’ll add the code to any page that the information is on).

The collection items wouldn’t be changing, only the fees field.

I have two fee items, “Individual Fee” and “Family Fee”

Perhaps in the text box, it could be set to replace a certain word or phrase such as {IND_FEE} and {FAM_FEE}.

For example, my text is something like:
“I agree to pay the fee of {IND_FEE} per term ({FAM_FEE} for families).”

I’ve tried a bunch of different ways, but to no success. The error I kept getting was that the dataset did not exist. I don’t have the code I was using as I deleted it and moved on, but can try to recreate it if necessary.

I’m fairly new to this language and this whole API system but have a basic understanding of what’s going on.

Would love any ideas around this.
Thanks!

I can send more information as required :slight_smile:

Hey Jeremy,

You can do what you are trying to set up, I can show you how.

If you have a dataset added to the page and set a variable to be the collections current item. You can then use this variable to use an exact field from the item to place in your text box.

In my example I have a collection of some products with a field called textPrice (which holds the price of the product). I added a dataset and a textbox to a page and I used this code to get and display the price.

$w.onReady(function () {
    $w("#dataset1").onReady( () => {
  console.log("The dataset is ready");
 let itemObj = $w("#dataset1").getCurrentItem();
  $w("#text5").text = "The price is " +  itemObj.textPrice + " today"
} );
})

When I preview the site is looks like this :

This way I can update the prices in my collection and I do not need to update the text boxes or code.

Hope this helps!

Dara | Corvid Team

Dear Dara, would you mind posting the code to display this in a repeater?