I have attempted several steps to create a custom block to display custom copyright text below the existing default copyright in the frontend.
In my module root directory (app/code/Ciptaloka/HelloWorld/
), I have these files added:
Block\Page\Footer\Copyright.php
- Block file<?php namespace Ciptaloka\HelloWorld\Block\Page\Footer; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Element\Template\Context; class Copyright extends Template { public function __construct( Context $context, array $data = [] ) { parent::__construct($context, $data); } public function getCopyrightTxt() { return __('All products displayed on this website are manufactured by Ciptaloka.com'); } }
view\frontend\templates\html\copyright.phtml
- Template file<small class="copyright"> <span><?= $this->getCopyrightTxt(); ?></span> </small>
view\frontend\layout\page_footer_copyright.xml
- Layout configuration file<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="copyright"> <block name="ciptaloka_helloworld.footer.copyright" class="Ciptaloka\HelloWorld\Block\Page\Footer\Copyright" after="-" template="html/copyright.phtml"/> </referenceContainer> </body> </page>
After creating those files, I tested it, but unfortunately it doesn't get displayed.
I want the frontend copyright footer to change from this:
<small class="copyright">
<span>Copyright © 2017 Magento, Inc. All rights reserved.</span>
</small>
to become this:
<small class="copyright">
<span>Copyright © 2017 Magento, Inc. All rights reserved.</span>
</small>
<small class="copyright">
<span>All products displayed on this website are manufactured by Ciptaloka.com</span>
</small>
My question is, can it be established by creating custom block on a custom module? If it can, and my codes got something wrong, can you point me out?
Thanks.
EDIT: My layout now looks like this, other files remain unchanged:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="before.body.end">
<block
name="ciptaloka_helloworld.footer.copyright"
class="Ciptaloka\HelloWorld\Block\Page\Footer\Copyright"
after="copyright"
template="html/copyright.phtml"/>
</referenceContainer>
</body>
</page>
But the result is not what I expected: my custom copyright is placed above the existing copyright message.