Home > OS >  Magento 2: syntax error, unexpected '"', expecting '-' or identifier (T_STR
Magento 2: syntax error, unexpected '"', expecting '-' or identifier (T_STR

Time:12-15

Could someone please tell me why am I getting the following error?

Parse error: syntax error, unexpected '"', expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /app/vendor/magenest/module-instagram-shop/view/frontend/templates/slider/slider.phtml on line 161 ?

The file is unmodified. PHP version: PHP 7.2.30 (cli) (built: Apr 23 2020 18:36:52) ( NTS ) short_open_tag = On. PHPStorm's code inspector is not throwing any issue.

I think it could be related to my environment settings. If i remove everything from the file (0 length), the page containing this widget renders properly. The module is properly set up in the backend. I am stumped. Thank you very much!

The line is

if ($widgetOptions["lazy_load"]) {

Full code:

<?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 
             id="slider-<?= $block->escapeHtmlAttr($prefixElementClass) ?>"
             style="display: none;">
            <div >
                <?= $block->getSharedPopupHtml($sliderBlock->getPhotoSource()) ?>
            </div>
            <div >
                <h2 ><?= $block->escapeHtml($sliderBlock->getTitle()) ?></h2>
            </div>
            <?= $storyBlock ?>
            <div >
                <div >
                    <?php if ($totalItems) { ?>
                        <div >
                            <ul 
                                <?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 ><ul >'
                                        );
                                    } ?>
                                    <li 
                                        id="<?= $block->escapeHtmlAttr($photo->getPhotoId()) ?>">
                                        <a href="<?= $block->escapeUrl($photo->getUrl()) ?>"
                                           <?php if (!$sliderBlock->isDefaultTemplate()) {
                                                echo '';
                                           } ?>>
                                            <?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 
                                                   style="
                                                        float: right;
                                                        margin: 5px;
                                                        font-size: 20px;
                                                        position: absolute;
                                                        right: 0;
                                                        top: 0">
                                                </i>
                                            <?php } ?>
                                            <div ></div>
                                            <div >
                                                <span >
                                                    <i >
                                                        <?= $block->escapeHtml($photo->getLikes()) ?>
                                                    </i>
                                                    <i >
                                                        <?= $block->escapeHtml($photo->getComments()) ?>
                                                    </i>
                                                </span>
                                                <p >
                                                    <?= $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 >
                                <a href="<?= $block->escapeUrl($sliderBlock->getUrl('instagram/gallery/')) ?>"
                                   style="<?= $sliderBlock->getViewFullGalleryCss() ?>"
                                   >
                                    <?= $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
} ?>

CodePudding user response:

The code is probably not written for 7.2 but since you're on 7.2 it should be enough to move script; at the beginning of the line:

[...]

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

  • Related