Question

I am trying to call a static block in the footer block but it does not work.

I created a theme and then created a default xml:

\app\design\frontend\MyTheme\Theme-frontend-default\Magento_Theme\layout\default.xml

i then removed the default footer links:

<referenceBlock name="footer_links" remove="true"/>

i then added the code to the block:

<referenceContainer name="footer">
            <block class="Magento\Cms\Block\Block" name="footer_navigation">
                <arguments>
                    <argument name="footerNavigation" xsi:type="string">footer_navigation</argument>
                </arguments>
            </block>
  </referenceContainer>

I had earlier created the block programmatically using an InstallData.php :

$cmsBlock = $this->blockInterfaceFactory->create();
        $cmsBlock->setIdentifier('footer_navigation')
            ->setTitle(self::Footer_Navigation)
            ->setContent('{{block class="Topclick\CmsPages\Block\Cmspages" template="Topclick_CmsPages::blockTemplates\footerNavigation.phtml"}}')    
            ->setData('stores', [0]);
        $this->blockRepository->save($cmsBlock);

so. i am unclear why its not working. i did however test the block and it does indeed render on normal pages using this:

echo $this->getLayout()
          ->createBlock('Magento\Cms\Block\Block')
          ->setBlockId('footer_navigation')
          ->toHtml();

Why my xml doesn't work ?

Was it helpful?

Solution

Please try with below code in your \app\design\frontend\MyTheme\Theme-frontend-default\Magento_Theme\layout\default.xml file.

I have called static block id "footer-custom-links". Please change with your static block id.

<?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-container">  
        <block class="Magento\Cms\Block\Block" name="footercustom-links" as="footercustom-links" after="-">
            <arguments>
                <argument name="block_id" xsi:type="string">footer-custom-links</argument>
            </arguments>
          </block>
    </referenceContainer>
  </body>

Thanks

OTHER TIPS

Change your xml by following code:


<referenceContainer name="footer">
    <block class="Magento\Cms\Block\Block" name="footer_navigation">
        <arguments>
            <argument name="block_id" xsi:type="string">17</argument>
        </arguments>
    </block>
</referenceContainer>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top