简体   繁体   中英

Prestashop Smarty language string inside a js file

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 "{ls='text'}"

in this place:

content += '<span class="pname">' + {l s='text'} + '</span>';

How can I make it work?

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>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM