0

Consider below code, the condition ko if: falg does not work. How to define variable falg = "false" in this file?

<!-- ko falg = "false" --> <!-- /ko -->
<!-- ko if: product_has_url -->
    <!-- ko falg = "true" --> <!-- /ko -->
<!-- /ko --> 
<!-- ko if: falg -->
...
<!-- /ko --> 

update: I'm writing module to customize the minicart content. Below is the structure:

   registration.php
    |   
    +---etc
    |   |   module.xml
    |   |   
    |   \---frontend
    |           di.xml
    |           
    +---Plugin
    |       DefaultItem.php
    |       
    \---view
        +---frontend
            \---layout
            |     checkout_cart_sidebar_item_renderers.xml
            |       
            \---web
              \---js
                 \---myscript.js
              \---template
                 \---minicart
                    \---item
                            default.html 
    \---requirejs-config.js

So now my challenge is to pass the flag from myscript.js to based on the item attibute product_has_url to default.html

myscript.js ?

define([
    'uiComponent',
    'Magento_Customer/js/customer-data',
    'jquery',
    'ko',
    'sidebar'
], function (Component, customerData, $, ko) {


    function checkAttr() {


    }

    return Component.extend({

        }); 

});
2

You can try this :

<!-- ko if: falg -->
...
...
<!-- /ko --> 
<!-- ko ifnot: falg -->
...
...
<!-- /ko --> 

In js file you can use like this :

 return Component.extend({.....}),
    initObservable: function () {
        var me = this;
        me.flag(true);
        return this;
    }, ....

After this you need to deploy static content or to test you can add changes directly in the same js and html file of pub/static.

| improve this answer | |
  • Thanks, I'll accept as answer but pls complete it with js script you mentioned. As the main issue is with assigning value to variable based on condition in ko template ;) – Zinat Nov 17 '16 at 11:13
  • The js file is dependent on your module which you are using. – Ashish Jagnani Nov 17 '16 at 11:14
  • Isn't the path in namesapce/moudlename/view/frontend/web/js/myscript.js ? – Zinat Nov 17 '16 at 11:18
  • I updated the question, pls let me know if you can help me with the js content in details. tnx – Zinat Nov 17 '16 at 14:08

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.