0

Hi in past i have raised

this issue on how to display image over breadcrumbs in catg and though i have found an ans by myself but i have also got an ans from peoples

but now am facing another related to this those catg images are visible any new cms page that i have created. for refrence am putting an image below enter image description here

breadcrumbs.phtml

<?php if ($crumbs && is_array($crumbs)) : ?>
<div class="breadcrumbs">


<?php
echo $this->getLayout()
->createBlock('Magento\Cms\Block\Block')
->setBlockId('catg-image')
->toHtml();
?>

    <ul class="items">
        <?php foreach ($crumbs as $crumbName => $crumbInfo) : ?>
            <li class="item <?= $block->escapeHtmlAttr($crumbName) ?>">
            <?php if ($crumbInfo['link']) : ?>
                <a href="<?= $block->escapeUrl($crumbInfo['link']) ?>"
                   title="<?= $block->escapeHtml($crumbInfo['title']) ?>">
                    <?= $block->escapeHtml($crumbInfo['label']) ?>
                </a>
            <?php elseif ($crumbInfo['last']) : ?>
                <strong><?= $block->escapeHtml($crumbInfo['label']) ?></strong>
             <?php else : ?>
                <?= $block->escapeHtml($crumbInfo['label']) ?>
            <?php endif; ?> 
            </li>
        <?php endforeach; ?>
    </ul>
</div>
<?php endif; ?>

and i dont want this image to be displayed in cms pages thanks in advance

2
  • You want to display images only in category pages. i m right? Dec 30 '19 at 7:00
  • yes exactly over breadcrumbs
    – Pramod
    Dec 30 '19 at 7:04
3

Replace your code with below code :



<?php if ($crumbs && is_array($crumbs)) : ?>
<div class="breadcrumbs">


<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$request = $objectManager->get('\Magento\Framework\App\Request\Http');

$moduleName = $request->getModuleName();
$controller = $request->getControllerName();
$action     = $request->getActionName();

if($moduleName == "catalog" && $controller == "category" && $action == "view") {
    echo $this->getLayout()
    ->createBlock('Magento\Cms\Block\Block')
    ->setBlockId('catg-image')
    ->toHtml();
}

?>

    <ul class="items">
        <?php foreach ($crumbs as $crumbName => $crumbInfo) : ?>
            <li class="item <?= $block->escapeHtmlAttr($crumbName) ?>">
            <?php if ($crumbInfo['link']) : ?>
                <a href="<?= $block->escapeUrl($crumbInfo['link']) ?>"
                   title="<?= $block->escapeHtml($crumbInfo['title']) ?>">
                    <?= $block->escapeHtml($crumbInfo['label']) ?>
                </a>
            <?php elseif ($crumbInfo['last']) : ?>
                <strong><?= $block->escapeHtml($crumbInfo['label']) ?></strong>
             <?php else : ?>
                <?= $block->escapeHtml($crumbInfo['label']) ?>
            <?php endif; ?> 
            </li>
        <?php endforeach; ?>
    </ul>
</div>
<?php endif; ?>

Hope this will help you!

7
  • ok sir am trying
    – Pramod
    Dec 30 '19 at 7:06
  • yep this works could you please explain your ans?? why mine was not working
    – Pramod
    Dec 30 '19 at 7:07
  • <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $request = $objectManager->get('\Magento\Framework\App\Request\Http'); $moduleName = $request->getModuleName(); $controller = $request->getControllerName(); $action = $request->getActionName();
    – Pramod
    Dec 30 '19 at 7:08
  • explain these??
    – Pramod
    Dec 30 '19 at 7:08
  • If your requested url is catalog/category/view then only call your block. means when any request comes from this url then only call this block Dec 30 '19 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.