0

I am displaying my banner on the page, it is displaying correct.

I want to show the Banner between the dates from the "display_from" to "display_to".

I am getting my all date in this code, above date is also getting.

I want to show the banner between the dates that are getting in the template:

My code:

/** @var \Vendor\BannerSlider\Model\Banner[] $bannerCollection */
$bannerCollection = $block->getBannerCollection();
//var_dump($bannerCollection);
?>
<div class="bf-banner-sliders-block">
    <div data-role="loader" class="loading-mask">
        <div class="loader">
            <img src="<?= /* @escapeNotVerified */ $block->getViewFileUrl('images/loader-1.gif'); ?>"
                 alt="<?= /* @escapeNotVerified */ __('Loading...') ?>">
        </div>
    </div>
    <div class="bf-banner-sliders no-display" id="bf-banner-sliders" data-block="bf-banner-sliders">

        <?php
      if





        foreach ($bannerCollection as $banner) :?>
            <div class="banner-slider slick-slider">
                <div class="banner-image">
                    <a href="<?= $banner->getBannerUrl()?: 'javascript:void(0);'?>">
                        <picture>
                            <!--[if IE 9]><video style="display: none;"><![endif]-->
                            <?php if ($imageDesktopUrl = $banner->getImageDesktopUrl()) :?>
                                <source srcset="<?= /* @escapeNotVerified */ $imageDesktopUrl;?>" media="(min-width: 1024px)">
                            <?php endif; ?>
                            <?php if ($imageTabletUrl = $banner->getImageTabletUrl()) :?>
                                <source srcset="<?= /* @escapeNotVerified */ $imageTabletUrl;?>" media="(min-width: 768px) and (max-width: 1023px)">
                            <?php endif; ?>
                            <?php if ($imageMobileUrl = $banner->getImageMobileUrl()) :?>
                                <source srcset="<?= /* @escapeNotVerified */ $imageMobileUrl;?>" media="(max-width: 767px)">
                            <?php endif; ?>
                            <!--[if IE 9]></video><![endif]-->
                            <img data-lazy="<?= /* @escapeNotVerified */ $imageDesktopUrl;?>" srcset="<?= /* @escapeNotVerified */ $imageDesktopUrl;?>" alt="<?= /* @escapeNotVerified */ $banner->getTitle();?>">
                        </picture>
                    </a>
                </div>
                <div class="banner-content <?= /* @escapeNotVerified */ $block->escapeHtml($banner->getAlignText()) ?>">
                    <h2 class="banner-title"><?= /* @escapeNotVerified */ $block->escapeHtml($banner->getTitle()) ?></h2>
                    <?php if ($banner->getDescription()) :?>
                        <div class="banner-inner <?= /* @escapeNotVerified */ $block->escapeHtml($banner->getAlignText()) ?>">
                            <span class="banner-caption"><?= /* @escapeNotVerified */ $banner->getDescription()?></span>
                        </div>
                    <?php endif;?>
                    <?php if ($banner->hasButton()) :?>
                        <?php $buttonUrl  = $banner->getButtonUrl();?>
                        <?php $buttonText = $banner->getButtonText() ?: __('Shop Now');?>
                        <div class="banner-button">
                            <a href="<?= /* @escapeNotVerified */ $buttonUrl ?: 'javascript:void(0);'?>"
                               title="<?= /* @escapeNotVerified */ $buttonText?>">
                                <span><?= /* @escapeNotVerified */ $buttonText?></span>
                            </a>
                        </div>
                    <?php endif;?>
                </div>
            </div>
        <?php endforeach;?>
    </div>
</div>
5
  • Just put if condition before foreach loop like If (current_date >= display_from && current_date <= display_to)
    – Pawan
    Commented Jul 28, 2023 at 6:15
  • it will works fine?
    – Rana Zain
    Commented Jul 28, 2023 at 6:38
  • Can you please include the condition, where you want to place the your condition in the phtml template?
    – Rana Zain
    Commented Jul 28, 2023 at 7:13
  • @RanaZain Could you demonstrate the code used to retrieve the display_from and display_to dates? Commented Oct 17, 2023 at 6:01
  • Sorry I can't understand what are you saying, can you please provide more details, I think you want to display the dates from the configurations into the templates frontend
    – Rana Zain
    Commented Oct 18, 2023 at 7:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.