I have Smarty variable (PrestaShop) {$cart_qties}
. How can I use it in a script?
For example
<script>
if ("{$cart_qties}" > 5) {
document.getElementById("demo").innerHTML = "MAS de 5";
}
</script>
<p id="demo">MENOS de 5</p>
I have Smarty variable (PrestaShop) {$cart_qties}
. How can I use it in a script?
For example
<script>
if ("{$cart_qties}" > 5) {
document.getElementById("demo").innerHTML = "MAS de 5";
}
</script>
<p id="demo">MENOS de 5</p>
You could use the {literal}{/literal}
keys to take into account the code Javascript
and leave the variable unplaced inside these keys, as indicated in the Smarty place :
{literal}
if ({/literal}{$cart_qties}{literal} > 5) {
document.getElementById("demo").innerHTML = "MAS de 5";
}
{/literal}
Very good, you have to bear in mind that the keys that are used to indicate that they are smarty variables, are also used in the javascript language, if you want to use a variable in javascript, the easiest thing would be something like this:
<script>
var numero = {$cart_qties};
{literal}
if (numero > 5) {
document.getElementById("demo").innerHTML = "MAS de 5";
}
{/literal}
</script>
As you can see, what I do is get the values before using the javascript keys, which are included within the literal tag.
Greetings, I hope I have helped.
for example this code works well
{if {$cart_qties} < 5 }
<span> menos de 5 </span>
{else}
<span> mas de 5 </span>
{/if}
But without innerHTML I have to refresh the page to update what has to appear. That's why I want to put it in script