I created one module. which have helper function which returns module is enabled or not? Now I want to check if this module is enabled or not in javascript for all pages on the frontend, for that, I want to set function value to config provider like "window.checkoutConfig.customvalue". Now I need like "window.catalog.customvalue" or any global javascript value which can be accessed from every page, How can I do this?

One more example for global config is "BASE_URL" when you write BASE_URL in the console it gives URL, I want the same functionality, just need to add that kind of variable in config.

I know how to set config provider in the checkout with "chckoutConfig" but I want to set that function value in common config provider so I can get that value in every js file or console.

If anyone has an idea about it?


Magento 2 has "head.additional" block, where you can set your variables globally.

Add below code in


$globalConfig = [];
$globalConfig['FirstVariable'] = 'My first value';
$globalConfig['SecondVariable'] = 'My second value';
    window.globalConfigData = <?php echo json_encode($globalConfig); ?>;

Then add below code in XML


<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceBlock name="head.additional">
            <block class="Magento\Framework\View\Element\Template" name="globalconfigvariable" template="Name_Module::globalvar/globalvariable.phtml"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.