Reputation: 1565
I am making some changes to the module "Blockcart" and I need to insert inside the ajax-cart.js file a language string, for example "{l s='text'}"
in this place:
content += '<span class="pname">' + {l s='text'} + '</span>';
How can I make it work?
Upvotes: 1
Views: 816
Reputation: 2733
There are several options to achieve the desired effect.
One option is to define the variable as a global one in the layout, eg. header HTML part of the page with
<script>
var pName = "{l s='text'}";
</script>
and then use it in the ajax-cart.js
with
content += '<span class="pname">' + pName + '</span>';
Another option is to use a data attribute:
Find a HTML wrapper element of the cart DOM and insert the following data attribute, or you can use any other accessible HTML element.
<div id="shopping-cart-wrapper" data-label-pname="{l text='text'}"></div>
Then in the ajax-cart.js
use:
content += '<span class="pname">' + $('#shopping-cart-wrapper').data('label-pname') + '</span>';
Upvotes: 1