1

This in a template file:

<script type="text/x-magento-init">
    {
        "*": {

            "component": {
                "my_config" : "<?php echo 0; ?>"
            }

        }
    }
</script>

will be transformed to a string in the component javascript file. This is really annoying because 0 is not a falsey value in js, so:

if(config.my_config){ ... }

will not work. This is just an example, there are others where you want to make sure you return integers and you lose time trying to debug what's happening.

1 Answer 1

1

Your code produce:

<script type="text/x-magento-init">
    {
        "*": {

            "component": {
                "my_config" : "0"
            }

        }
    }
</script>

But looks like you need:

<script type="text/x-magento-init">
    {
        "*": {

            "component": {
                "my_config" : 0
            }

        }
    }
</script>

So write code like:

<script type="text/x-magento-init">
    {
        "*": {

            "component": {
                "my_config" : <?php echo json_encode(0); ?>
            }

        }
    }
</script>
0

Your Answer

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

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