0

I have created a block within my new theme, but it is showing on all pages, I need it to only show on the home page and when logging in or going to another page it does not show

create it inside default.xml

<container name="copyright.container" as="copyContainer" label="Copyright Container" htmlTag="div" htmlClass="copyright-container">
        <block class="Magento\Framework\View\Element\Template" name="copyright__container" template="Magento_Cms::copy.phtml" />
</container>

on mi file .phtml

<div class="copy">
<span>
    <?php $Object = new DateTime();
        $anio = $Object->format("Y"); 
        echo "Copyright © $anio Agriconecta"; ?>  
</span>

I need it to only show on the home page and not on the other pages,

1 Answer 1

0

You can create a block from Admin and then call it in your PHTML file

Admin > Content > Blocks > Add New Block

There you can add the html:

  <div class="copy">
<span>
   Copyright © 2021 Agriconecta.
</span> </div>

Then, in your PHTML file you call the block with this line:

<?= $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('HERETHEBLOCKIDENTIFIER')->toHtml();?>
2
  • it works, but I don't get the styles I declare in app / design / frontend / Theme / Theme / Magento_Theme / web / css / source / _extend.css
    – geracros
    Aug 9, 2021 at 22:59
  • _extend.css is an static file, so you have to create a new .Less file at web/css then you have to import it in _extend.less as "@import '../_MyCssFile.less';" After that, you must deploy static content "bin/magento setup:static-content:deploy" Aug 9, 2021 at 23:36

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.