Mustache Module

I recently started using the Mustache module and noticed that in the example syntax under the variables field, it says
'Enter the array'.[{"key":"<key1>","value":"<value1>"},["key"."<key2>","value":" <value2>"},....]'

Could someone please provide an example of how to use a keyed array, as demonstrated in the example text below the field? Please demonstrate the usage of the keyed array and how to replace the handlebar items in the template with the items from the keyed array. I assume that the ‘key’ refers to what is in the handlebar, and the ‘value’ will be the result after it is replaced. I am unsure about how to properly include the array in the field. I attempted to simply drop it in using a clicked reference, but I believe it might require a map function or something similar.

Hi @Tony42!

To build the array you could use the add() array function as I described in a completely different use-case here.

Note though that in the case of the Mustache module, each array element is a collection. You’d need to create the appropriate JSON object for that collection using the Create JSON module.

1 Like

Thank you for the reply I created a JSON object with a collection and two items the key and value i want replace. Is this what I need? Now how do I implement from here?

If you look closely at the example syntax, you’ll see that the key object needs to be named key rather than textKeyword, and the value needs to be named value rather than textReplacement.

Also, I think the key should be stated without any curly mustache braces, as shown in the help.

If you can make those changes in your Jotform that would be easiest - then you can just map the textReplacements array from the Parse JSON module straight into the Mustache module.

2 Likes

How about this issue? I switched the mustache text to mappable. I assume that means I placed the handlebar text inside the mapped items. As you can see in the screenshot, I tried two versions. Since I can’t use double handlebars {{ }} in make.com, I attempted one version with the handlebars escaped as {{name}}. This is indicated as “1” in the screenshot. Then, I tried another version of the text using double handlebars {{name}} which transformed it into a mapped item for make, as shown as “2” in the screenshot. However, neither version worked, so I have no idea how to pass a variable of text and have it modified.

That’s a very good question. The Help documentation for the Mustache module doesn’t mention the Mappable Template Mode, so there’s no hints there. I’ll enquire.

However … from your example it looks like you’re trying to create a JSON object. It might be simpler to use the Parse JSON module from within the JSON app.

2 Likes

Thank you, please let me know when you hear back about the usage syntax.

Yeah, it might be easier to use the JSON parser. However, I have a specific use case for the mustache module in this scenario, and I hope it can be utilized.

It seems that the original concept was that the mapped Template would come from some other source where the {{ and }} was already in place.

If you’re assembling the Template in a Set a Variable module then you will run into the issue of {{ and }} being treated specially by the UI. The most practical workaround for this is to use something else that doesn’t get recognized by the UI and then replace it using a function.

For example, if you wanted:

{{value}}

you could instead use:

replace({{value]];];})

As the value hasn’t been wrapped in curly braces it doesn’t get recognized by the UI. The replace() function changes it to the correct syntax.

Let us know how you get on!

2 Likes