Javascript variables

In this article:


    The front end of the shop exposes a number of JavaScript variables that the system uses in the JavaScript code. These variables can be used by developers to develop their own JavaScript components. The variables are placed on the window elementet

    and are reviewed below.

    The variables below can be found with DOM inspector. See our guide to variables for a basic introduction.

     

    The Platform variable

    • currency -contains currency data such as symbol, decimal, etc.
    • general -contains general data such as domain, site/language ID, etc.
    • language -contains language data as ISO language code.
    • page -contains page data such as page type, ID, etc.
    • settings -contains settings saved in the control panel.
    • template -contains template data such as name, domains and settings.
    • user - contains user data if logged in.

    Platform functions

    • subscribe - function to listen to events, e.g. on the item card (variant selection)
    • unsubscribe - function to remove a subscription on events.
    • publish -function to send events, e.g. on the item card.
    • currency_format - function to format currency.
    • number_format - Javascript implementation of PHP's number_format for formatting numbers.

    For products, the following is exposed:

    • product -contains product data such as title, price, link, etc.

    The text variable

    • Contains all text translations for the selected language layer.

    The template variable

    • Includes break-points for the template.

    Template functions

    • bp.current - function that tells you which TorqueUI breakpoint you are on ('xl', 'l', 'm' eller 's')