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,

asked Aug 9, 2021 at 18:13

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();?>
answered Aug 9, 2021 at 20:45
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 Commented 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" Commented Aug 9, 2021 at 23:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.