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
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();?>
-
it works, but I don't get the styles I declare in app / design / frontend / Theme / Theme / Magento_Theme / web / css / source / _extend.cssgeracros– geracros2021年08月09日 22:59:22 +00:00Commented 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"Luis Castellanos– Luis Castellanos2021年08月09日 23:36:42 +00:00Commented Aug 9, 2021 at 23:36