Using External Variable in Javascript/Jquery

Asked

Viewed 123 times

1

Good morning!

On the website of the company I work, there are certain variables like this: {{order_total}}

In this case, I need to make a simple script, to take the total value and add an HTML in front...

 $JQuery(function(){
var valordopedido = {{order_total}};
if(valordopedido >= 299){
    $JQuery('<div class="msg-free_shipping"> <p><span class="warning">ATENÇÃO:</span> Comprando mais <span class="restante">R$259,10</span> você aproveita o <strong>FRETE GRÁTIS</strong> nas compras acima de <span class="valor-gratis">R$299,00</span></p> </div>').insertAfter('form#cart_update_post');
}});

Only it keeps giving the error: Uncaught Syntaxerror: Unexpected token {

Someone could help?

Thank you!

  • Actually this would not be a variable, but an expression. Are you using any framework? These expressions can be treated as variables within their scope in the business part, not in the view part. But specifying which language you are using and if you are using any framework, it is easier to help you.

  • The site is developed on top of Magento, Gabriel!

2 answers

1

The error message is warning the syntax {{order_total}} is wrong, that should not have the { there.

If the variable exists in the scope you are in just use like this:

var valordopedido = order_total;

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.