Mehtab
Mehtab

Reputation: 473

How to show JS variable in bigcommerce handlebar?

<script>
var x = "i am the value";
</script>
<a href="{{url}}" class="breadcrumb-label" itemprop="item"><span itemprop="name">x is : {{x}} </span></a>

I think x should show some output but it is displaying empty when rendering. anyone can tell me how can I show the js variable in bigcommerce handlebar template

Upvotes: 0

Views: 490

Answers (1)

jdswift
jdswift

Reputation: 208

I'm not certain what you're trying to do, the value in the script element is not available at the time the handlebars template is rendered. The handlebars template is processed by bigcommerce to give html to the user's browser, the user's browser then executes the javascript in the script tag.

If you want to have an element on the page reflect the value of a javascript variable, you'd need to do that yourself (e.g. with a onload event).

If you want to be able to determine the value of a stencil handlebars value, you can use assign.

{{assign "x" "i am the value"}}
<a href="{{url}}"><span itemprop="name">x is : {{x}} </span></a>

Upvotes: 3

Related Questions