Skip to content
Advertisement

Disable swiper.js autoplay using inline if statement

Im trying to disable the swiper autoplay depending on a widget name parameter that gets me the a value. (Im using magento widget and i get the value from the widget.xml) Here is a example:

simulateTouch: <?= ($block->getData('is_gestures') == "1") ?'true':'false'?>,
               // ---- gestures end -----
            freeMode: true,
                    // --- infinite loop -----
            loop: <?= ($block->getData('infiniteLoop') == "1") ?'true':'false'?>,
                    // --- autoplay ----
             autoplay: {
              delay: 2500,
              disableOnInteraction: false,
             },

with the other values its easy because its a true of false but in this case i need that code to appear if my $block->getData(‘autoplay’) == “1” but i cant figure out how to do it i tried

<?= ($block->getData(‘autoplay’) == "1") ?{  delay: 2500,  disableOnInteraction: false,  },:''?>, or with the code inside '' but it bugs my swiper all the time

Advertisement

Answer

<?= ($block->getData(‘autoplay’) == "1") ?'{  delay: 2500,  disableOnInteraction: false,  }':'false'?>,

The solution was wrapping the code that belongs to autoplay == 1 in ” and before the : is false and it works that way

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement