3

I'm trying to add custom template from my custom module.

Layout file: app/code/Foo/Bar/view/frontend/layout/default.xml

<?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="footer">
            <block class="Foo\Bar\Block\FooterTest" name="footer_assets" template="footer/test.phtml" />
        </referenceContainer>
    </body>
</page>

my template: app/code/Foo/Bar/view/frontend/templates/footer/test.phtml

<span>test</span>

When i rename layout file from default.xml to cms_index_index.xml then template is displayed, but only on home page. What i have to change to display this template on all pages?

1

In you default.xml you can add after="footer_links" and mention your module template like "Foo_Bar::footer/test.phtml"

I have tried below code and working fine for me.

<?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="footer">
        <block class="Foo\Bar\Block\FooterTest"  name="footer_assets" after="footer_links" template="Foo_Bar::footer/test.phtml"/>
            </referenceContainer>
        </body>
    </page>

Hope this answer will help.

0

Change default.xml

<?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="footer">
            <block class="Foo\Bar\Block\FooterTest" name="footer_assets" template="Foo_Bar::footer/test.phtml" />
        </referenceContainer>
    </body>
</page>

And make sure your block class is [Foo\Bar\Block\FooterTest.php]

namespace Foo\Bar\Block;

class FooterTest extends \Magento\Framework\View\Element\Template
{

}
0

@krishna ijjada @Sohel Rana thx for help but cause was in another place. First i tried add this template in my custom theme and then i was added it by module. When i removed it from default.xml in theme then it has been started work by my module.

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.