Liquid Variables inside JavaScript Tags. (Recharge)

Topic summary

A store using the Recharge app (subscription tool) wants to show product metafield values beneath dynamically generated product images. The page is modified by appending HTML via JavaScript inside a Recharge-specific Liquid block {% javascript %}, while Liquid is Shopify’s templating language used to render variables server-side.

The author attempted to assign a Liquid variable (testText = “New!”) outside the {% javascript %} block and then reference it within the JavaScript using variations like var myVar = {{testText}}, {{testText | json}}, and quoted forms. None produced output when inserted into innerHTML.

Key issue: whether Liquid-rendered variables/metafields can be accessed within Recharge’s JavaScript tag context, and if so, how to correctly pass values into the client-side script.

Artifacts central to understanding: the specific Liquid-to-JS interpolation attempts.

Status: no resolution or guidance provided yet; the question remains open on feasibility and approach.

Summarized with AI on January 13. AI used: gpt-5.

In our store we are using the Recharge App, which dynamically generates the products on a grid.
The only option I have to visually modify the page is to create HTML elements and append them to the corresponding element.
The way I do this is in the JavaScript tags in the Recharge liquid file {% javascript %}.
Now I want to use the metafields of the products to insert the value of the metafield under the picture of the product.

I tried to assign a test variable in Liquid:

{% assign testText = "New!" %}

outside of the {% javascript %} tags and then to retrieve it inside the{% javascript %} tags. But it’s impossible to make it show up.
I also tried every possible solution out there:

var myVar = {{testText | json}};
var myVar = {{testText }};
var myVar = "{{testText | json}}";
var myVar = "{{testText }}";

and then adding it to an innerHTML.

I would like to know if this is even possible? If yes, how would I proceed?

Thank you in advance.