1

I want to know if you can get the config value to html I have a class which provides the value for config Not sure how to get this checked in HTML

I have been looking at configproviderinterface

4
  • you can only do it using ko js
    – fmsthird
    Commented Apr 23, 2019 at 11:05
  • Is there any example I could take a look at, I have tried few but still no luck Commented Apr 23, 2019 at 11:15
  • check this magento.stackexchange.com/questions/258408/…
    – fmsthird
    Commented Apr 23, 2019 at 11:18
  • Thanks for that magefms, but I am not sure how that would pick up the config value from the admin. I have yes or no option in config if the value is yes I want to show in html if it’s not then show nothing. I have a class which checks the config not sure how that would get to html Commented Apr 23, 2019 at 11:21

2 Answers 2

1

Override DefaultItem customer data Magento\Checkout\CustomerData\DefaultItem And you can call the additional to KOJS This should allow you to grab the config value

protected function doGetItemData() {
//add new here 
e.g.
'check_enabled' => $this->Helper->getNewPrice(),
}

In you html

< !-- ko if: check_enabled ==1 -->
//do  h tag which does test
< !-- ko -->

< !-- ko ifnot: check_enabled ==1 -->
do  h tag which does testfailed
<!-- ko -->
1

I'll give an example for checkout page, the idea is to load your config module in phtml, then you call that phtml in html

  1. We create our phtml:

    app/design/frontend/{Vendor}/{theme}/Magento_Checkout/templates/html/my-custom.phtml

    //you get your config module here then save it in $config 
    
     <?php echo $config; ?>
    
  2. We instantiate our custom phtml:

    app/design/frontend/{Vendor}/{theme}/Magento_Checkout/templates/onepage.phtml

    /* The Magento onepage code first, 
    then we add our myphtml var bellow the initial file code, 
    this file if you haven't it yet in your current theme, 
    you can copy it from :
    vendor\magento\module-checkout\view\frontend\templates\onepage.phtml*/
    
    
    ...
    
    <?php $myphtml = $block->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magento_Theme::html/my-custom.phtml")->toHtml(); ?>
    
    <script type="text/javascript">
        var my_phtml = <?php echo json_encode($myphtml); ?>;
    </script>
    
  3. We go to our html then bind our phtml content

    for exmple: we get our phtml in shipping.html file:

    app/design/frontend/{Vendor}/{theme}/Magento_Checkout/web/template/shipping.html

    ...
    
    <div id="my-id" title="Information" data-bind="html:my_phtml"/> // here you get your config module value
    

I not tested it but it should work !

1
  • Hi Prince, I can’t use that I have tried it and that’s for checkout. I was doing it for minicart but I really appreciate it Commented Apr 23, 2019 at 11:50

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.