I have a document where an HTML string contains text with embedded dates. Assuming I can wrap each date in a span and give them the same class, I want a Script in the template that will format all the dates.
This is slightly different than formatting a Date field or fields. I don’t want to replace any values with values out of the Data Model. I want my script to iterate over the class members, extract the html, format the html in a specific date format, and then replace the original date with the formatted date.
On a web page, for example, I could do this:
const collection = document.getElementsByClassName("myDate");
for (let i = 0; i < collection.length; i++) {
myDateSTR = collection[i].innerHTML;
myDate = new Date(myDateSTR).toLocaleDateString('es-US', { day: '2-digit', month: '2-digit', year: 'numeric' })
collection[i].innerHTML = myDate;
What would an equivalent “Standard Script” look like in Connect?