0
<span class="aem-image-with-borders-container" 
data-bind="scope: 'catalog-image'">
<!-- ko template: getTemplate() --><!-- /ko -->
<script type="text/x-magento-init">
        {
          ".aem-image-with-borders-container": {
              "Magento_Ui/js/core/app": {
                  "components": {
                      "catalog-image": {
                          "component": "SccService_AemDam/js/catalog-image",
                          "template": "SccService_AemDam/image_with_borders",
                          "aemConfig": {
                                                "url": "http://local.sig.com/test/test.json",
                                                "placeholder": ""
                            },
                            "fallback": "<?= /* @escapeNotVerified */ $block->getImageUrl() ?>",
                            "imageData": {
                              "width": "<?= /* @escapeNotVerified */ $block->getWidth() ?>",
                              "ratio": "<?= /* @escapeNotVerified */ ($block->getRatio() * 100) ?>",
                              "imageWidth": "<?= /* @escapeNotVerified */ $block->getResizedImageWidth() ?>",
                              "imageHeight": "<?= /* @escapeNotVerified */ $block->getResizedImageHeight() ?>",
                              "alt": "<?= /* @escapeNotVerified */ $block->stripTags($block->getLabel(), null, true) ?>"
                            }
                      }
                  }
              }
          }
        }
</script>

Attempting to use knockout js for the first time. Attempting to pass data from PHP block into the js. The js logic is being called as many times as this template renders an image - however, the PHP logic is only being called once - or the PHP logic renders only the last image data.

For context, this phtml is being rendered 10 times. The JS script at js/catalog-image runs 10 times. Each time, $block->getImageUrl() is setting this.fallback to the same url - inside the phtml script.

Is there a way to set params via PHP so that the knockout js script may pick it up? I feel I'm missing something - any direction would be helpful.

Your Answer

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

Browse other questions tagged or ask your own question.