Magento 2:语法错误,在phtml文件中出现意外的“”,预期为“-”或标识符(T_STRING)或变量(T_VARIABLE)或数字(T_NUM_STRING)

u5rb5r59  于 2022-11-12  发布在  其他
关注(0)|答案(1)|浏览(184)

有人能告诉我为什么会出现以下错误吗?
分析错误:语法错误,第161行上的/app/vendor/magenest/module-instagram-shop/view/frontend/templates/slider/slider.phtml中出现意外的“”,应为“-”或标识符(T_STRING)或变量(T_VARIABLE)或数字(T_NUM_STRING)?
该文件未修改. PHP版本:PHP 7.2.30(客户端)(构建版本:Apr 23 2020 18:36:52)(NTS)short_open_tag = On. PHPSorm的代码检查器没有抛出任何问题。
我想这可能与我的环境设置有关。如果我删除文件中的所有内容(长度为0),包含此小部件的页面将正确呈现。该模块在后端设置正确。我被难住了。非常感谢!
这条线是

if ($widgetOptions["lazy_load"]) {

完整代码:

<?php
if ($sliderBlock = $block->getSliderBlock()) {
    $widgetOptions = $sliderBlock->getWidgetOptions();
    $photos = $sliderBlock->getPhotos();
    $slickConfig   = $sliderBlock->getData();
    $totalItems    = $photos->getSize();
    $itemsPerSlide = $sliderBlock->getItemsPerSlide();

    $prefixElementClass = uniqid();

    $storyBlock = $sliderBlock->getStoryBlock(); ?>
    <!--    allow show widget if photos is not null -->
    <?php if ($photos->getSize() != 0 || $storyBlock != '') { ?>
        <div class="photo-slider-wrapper"
             id="slider-<?= $block->escapeHtmlAttr($prefixElementClass) ?>"
             style="display: none;">
            <div class="slider">
                <?= $block->getSharedPopupHtml($sliderBlock->getPhotoSource()) ?>
            </div>
            <div class="block-title">
                <h2 class="title"><?= $block->escapeHtml($sliderBlock->getTitle()) ?></h2>
            </div>
            <?= $storyBlock ?>
            <div class="block-content">
                <div class="block block-photo-slider slider-list container">
                    <?php if ($totalItems) { ?>
                        <div class="photos-wrapper">
                            <ul class="photos-slick slick-<?= $block->escapeHtmlAttr($prefixElementClass) ?>"
                                <?php
                                if ($widgetOptions["rtl"] == "true") {
                                    echo ("dir='rtl'");
                                }
                                ?>>
                                <?php
                                $count = 0;
                                /**@var \Magenest\InstagramShop\Model\Photo $photo */
                                foreach ($photos as $photo) {
                                    if (!$sliderBlock->isDefaultTemplate() && $count % $itemsPerSlide == 0) {
                                        echo $block->escapeHtml(
                                            '<li class="slide-item"><ul class="'
                                            . $block->getItemsPerSlideClass()
                                            . '-photo">'
                                        );
                                    } ?>
                                    <li class="<?= $block->escapeHtmlAttr($photo->getPhotoId()) ?>
                                               instagram-photo
                                               <?php if ($sliderBlock->isDefaultTemplate()) {
                                                    echo 'default';
                                               } ?>"
                                        id="<?= $block->escapeHtmlAttr($photo->getPhotoId()) ?>">
                                        <a href="<?= $block->escapeUrl($photo->getUrl()) ?>"
                                           <?php if (!$sliderBlock->isDefaultTemplate()) {
                                                echo 'class="instagram-link-photo"';
                                           } ?>>
                                            <?php if ($widgetOptions["lazy_load"]): ?>
                                                <img data-lazy="<?= $sliderBlock->getPhotoSourceOptimize($photo) ?>"
                                                     alt=""/>
                                            <?php else: ?>
                                                <img src="<?= $sliderBlock->getPhotoSourceOptimize($photo) ?>" alt=""/>
                                            <?php endif; ?>
                                            <?php if ($photo->getMediaType() == 'VIDEO') { ?>
                                                <i class="fas fa-video"
                                                   style="
                                                        float: right;
                                                        margin: 5px;
                                                        font-size: 20px;
                                                        position: absolute;
                                                        right: 0;
                                                        top: 0">
                                                </i>
                                            <?php } ?>
                                            <div class="overlay"></div>
                                            <div class="text">
                                                <span class="widget-icon">
                                                    <i class="far fa-heart">
                                                        <?= $block->escapeHtml($photo->getLikes()) ?>
                                                    </i>
                                                    <i class="far fa-comment">
                                                        <?= $block->escapeHtml($photo->getComments()) ?>
                                                    </i>
                                                </span>
                                                <p class="photo-caption">
                                                    <?= $block->getPhotoCaption($photo->getCaption()) ?>
                                                </p>
                                            </div>
                                        </a>
                                        <?=  $sliderBlock->getLinkedProductsHtml($photo) ?>
                                        <?= $sliderBlock->getHotspotHtml($photo) ?>
                                        <?php if ($sliderBlock->canShowVideo()) {
                                            echo $sliderBlock->getVideoHtml($photo);
                                        } ?>
                                    </li>
                                    <?php
                                    $count++;
                                    if (!$sliderBlock->isDefaultTemplate()
                                        && ($count % $itemsPerSlide == 0 || $count == $totalItems)) {
                                        echo ('</ul></li>');
                                    }
                                } ?>
                            </ul>
                        </div>
                        <?php if ($sliderBlock->displayGalleryButton()): ?>
                            <div class="gallery-btn-block">
                                <a href="<?= $block->escapeUrl($sliderBlock->getUrl('instagram/gallery/')) ?>"
                                   style="<?= $sliderBlock->getViewFullGalleryCss() ?>"
                                   class="instagram-button">
                                    <?= $block->escapeHtml($sliderBlock->getViewFullGalleryTitle()) ?>
                                </a>
                            </div>
                        <?php endif; ?>
                    <?php } ?>
                </div>
            </div>
        </div>
    <?php } ?>

    <?php if ($photos->getSize()):
        $scriptString = <<<script
            require([
                'jquery',
                'photoModel',
                'slick'
            ], function ($, photoModel) {
                let item_number = {$block->escapeHtml($widgetOptions["items_number_desktop"])},
                    photos      = {$sliderBlock->getPhotosData($photos)},
                    photoSize   = {$block->escapeHtml($totalItems)};
                $('#slider-{$block->escapeHtml($prefixElementClass)}').on('init', function () {
                    $(this).attr('style', 'display: block;');
                });
                $('.photos-slick.slick-{$block->escapeHtml($prefixElementClass)}')
                    .on('afterChange', function (event, slick, currentSlide) {
                        //currentSlide is undefined on init -- set it to 0 in this case (currentSlide is 0 based)
                        let i = (currentSlide ? currentSlide : 0) + 1;
                        // no dots -> no slides
                        if (slick.\$dots) {
                            // use dots to get some count information
                                dotsLength = (slick.\$dots[0].children.length);
                            if (i == dotsLength) {
                                $(this).slick('slickGoTo', 0, true);
                            }
                        }
                        if (i <= photoSize) {
                            let iterator = item_number + 20, photo = [];
                            for (var j = 0; j < iterator; j++) {
                                if(typeof photos[i+item_number] != 'undefined') {
                                    photo.push(photos[i+item_number]);
                                    i++;
                                }
                            }
                            photoModel.setPhotos(photo);
                        }
                    });

                $('.photos-slick.slick-{$block->escapeHtml($prefixElementClass)}').slick({
                    slidesToShow: {$widgetOptions["items_number_desktop"]},
                    slidesToScroll: {$widgetOptions["slides_to_scroll"]},
                    infinite: false,
                    dots: {$block->escapeHtml($widgetOptions["animation_dots"])},
                    arrows: {$block->escapeHtml($widgetOptions["animation_arrows"])},
        script;
        if ($widgetOptions["lazy_load"]) {
            $scriptString .= <<<script
                    lazyLoad: 'ondemand',
            script;
        }
        $scriptString .= <<<script
                    autoplay: {$block->escapeHtml($widgetOptions["autoplay"])},
                    autoplaySpeed: {$block->escapeHtml($widgetOptions["autoplaySpeed"])},
                    rtl: {$block->escapeHtml($widgetOptions["rtl"])},
                    responsive: [
                        {
                            breakpoint: 1023,
                            settings: {
                                slidesToShow: {$widgetOptions["items_number_tablet"]},
                            }
                        },
                        {
                            breakpoint: 640,
                            settings: {
                                slidesToShow: {$widgetOptions["items_number_mobile"]},
                            }
                        }
                    ]
                }).slick('setPosition');
            });
            require(['mage/url'], function (urlBuilder) {
                return urlBuilder.setBaseUrl('{$block->escapeUrl($sliderBlock->getBaseUrl())}');
            });
        script;
        ?>
        <?= isset($secureRenderer)
        ? $secureRenderer->renderTag('script', [], $scriptString, false)
        : "<script>$scriptString</script>" ?>

        <?php
        $canShowVideo = $sliderBlock->canShowVideo() ? 'true' : 'false';
        $scriptString = <<<script
        {
            "#slider-{$block->escapeHtml($prefixElementClass)}": {
                "instagramPopup": {
                    "photos" : {$sliderBlock->getPhotosData($photos, true)},
                    "canShowVideo": {$canShowVideo},
                    "prefixContainer":".slider",
                    "prefixElement":"ul.slick-{$block->escapeHtml($prefixElementClass)} li",
                    "photoType": {$block->escapeHtml($sliderBlock->getPhotoType())},
                    "prefixElementClass": "#slider-{$block->escapeHtml($prefixElementClass)}",
                    "baseMediaUrl": "{$block->escapeUrl($block->getBaseMediaUrl())}"
                }
            }
        }
        script;
        ?>
        <?= isset($secureRenderer)
        ? $secureRenderer->renderTag('script', ['type' => 'text/x-magento-init'], $scriptString, false)
        : "<script type='text/x-magento-init'>$scriptString</script>" ?>
    <?php elseif ($storyBlock != ''):
        $scriptString = <<<script
            require(['jquery'], function ($) {
                $('#slider-{$block->escapeHtml($prefixElementClass)}').css('display', 'block');
            })
        script;
        ?>
        <?= isset($secureRenderer)
            ? $secureRenderer->renderTag('script', [], $scriptString, false)
            : "<script>$scriptString</script>" ?>
    <?php endif; ?>
    <?php
} ?>
i7uq4tfw

i7uq4tfw1#

这段代码可能不是为7.2编写的,但由于您使用的是7.2,因此将script;移到行首就足够了:
[...]
结束标识符可以缩进空格或制表符,在这种情况下,缩进将从文档字符串的所有行中去除。在PHP 7.3.0之前,结束标识符必须从行的第一列开始。
[...]
Heredoc的文档页面

相关问题