Use External Variable in JavaScript / JQuery

1

Good morning!

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

In case, I need to make a simple script, to get the total value and add an HTML up 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');
}});

It just gives the error: Uncaught SyntaxError: Unexpected token {

Would anyone help?

Thank you!

    
asked by anonymous 17.02.2017 / 14:06

2 answers

1

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

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

var valordopedido = order_total;
    
17.02.2017 / 14:21
1

When you have these variables in braces, I see the staff using replace, see if the link below makes it clearer.

link

    
17.02.2017 / 14:47