Magento 2:phtml 文件中的语法错误、意外的 '"'、预期的 '-' 或标识符 (T_STRING) 或变量 (T_VARIABLE) 或数字 (T_NUM_STRING)

Magento 2: syntax error, unexpected '"', expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in phtml file

有人能告诉我为什么会出现以下错误吗?

解析错误:语法错误,意外的'"',期待'-'或标识符(T_STRING)或变量(T_VARIABLE)或[=中的数字(T_NUM_STRING) 27=].phtml 第 161 行 ?

文件未修改。 PHP 版本:PHP 7.2.30 (cli)(内置:2020 年 4 月 23 日 18:36:52)(NTS) short_open_tag = 打开。 PHPStorm 的代码检查器没有抛出任何问题。

我想这可能与我的环境设置有关。如果我从文件中删除所有内容(长度为 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
} ?>

代码可能不是为 7.2 编写的,但由于您使用的是 7.2,因此应该足以在行的开头移动 script;

[...]

The closing identifier may be indented by space or tab, in which case the indentation will be stripped from all lines in the doc string. Prior to PHP 7.3.0, the closing identifier must begin in the first column of the line.

[...]

Heredoc's doc page