1

I want to see if my module is enabled in config are through html using Knockout JS.

ko if: module_enabled ==1 show a button if not don't show a button But i get this following error Uncaught ReferenceError: Unable to process binding "if: function(){return module_enabled() }" Message: module_enabled is not defined

2 Answers 2

1

got the answer

 <type name="Magento\Checkout\Model\CompositeConfigProvider">
        <arguments>
            <argument name="configProviders" xsi:type="array">
                <item name="additional" xsi:type="object">{module_name}\Model\AdditionalConfigProvider</item>
            </argument>
        </arguments>
    </type>

/**
 * Retrieve assoc array of checkout configuration
 *
 * @return array
 */
public function getConfig()
{
    return [
        'foo' => [
            'bar' => 'data',
        ],
    ];
}

this is the js file

 getSampleTotal: function () {;
                return window.checkoutConfig.foo.bar;
            }

html ko file

<p data-bind="html: getSampleTotal()"></p>
0

It is possible to also do it directly on the HTML ko file:

<p data-bind="html: window.checkoutConfig.foo.bar"></p>

You can also use it as a condition to display data:

<!-- ko if: (checkoutConfig.customerData.foo.bar == 1)-->
<p data-bind="html: 'some text"></p>
<!-- /ko -->

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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