首页 > 解决方案 > 使用内联 if 语句禁用 swiper.js 自动播放

问题描述

我试图根据一个小部件名称参数来禁用刷卡器自动播放,这让我得到了一个值。(我使用 magento 小部件,我从 widget.xml 中获取值)这是一个示例:

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,
             },

使用其他值很容易,因为它是假的,但在这种情况下,如果我的 $block->getData('autoplay') == "1" 我需要显示该代码,但我不知道该怎么做我试过

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

标签: phpmagentoswiper

解决方案


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

解决方案是将属于 autoplay == 1 的代码包装在 '' 中,并且在 : 为 false 之前,它以这种方式工作


推荐阅读