Using template variables in JavaScript


How do we go about using the variables defined within a template in JavaScript?

Let’s say I have the following line: jQuery("input[name='completion_redirect']").attr( "value", "*{Get name=myVariableComesHere}*" );

How would I go ahead implementing something like this?

I didn’t find any documentation to support JavaScript.

Hi Kendell,

Sorry for the late reply! There’s a feature called JS Variables, which can pass values from a template to its script. It’s documented here: Get and Set | Tangible Loops & Logic

You can pass a string/text value, like this:

<Set js=variable_name>Hello</Set>

Or other value type like number:

<Set js=variable_name type=number>123</Set>

And access it from the Script section:

console.log( variable_name )

The above will output the value in the developer’s console.

1 Like

Hi @eliot,

Thank you for your reply on this. I tried it and it works well.

Awesome. I love it!