0

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 ?

  • <?php echo $this->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('footer_navigation')->toHtml(); ?> doesn't work after clearing cache ? – PЯINCƏ Nov 22 '18 at 13:47
  • First confirm that, your block created or not? – Dhiren Vasoya Nov 22 '18 at 13:53
  • hi @DhirenVasoya-- i did indeed test whether it was created. it is.i rendered your code and it showed up – theSeeker Nov 22 '18 at 13:59
0

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

  • and which one is the name="block_id". is that just a random name? – theSeeker Nov 22 '18 at 17:35
  • No, "block_id" means it will pass "CMS Block ID" as argument. And replace "footer-custom-links" with your actual CMS Static block ID. So, your static block will display in footer section. – Darsh modi Nov 23 '18 at 3:55
0

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>
  • hi Sohel. i tried your code but its does not work. do you have any idea how i can go about debugging this. – theSeeker Nov 22 '18 at 14:07
  • This is working fine for me. Did you change your correct block_id, replace 17 to your and clear cache. – Sohel Rana Nov 22 '18 at 14:11
  • Open Magento\Cms\Block\Block, debug inside _toHtml. Don't forget to clear cache. – Sohel Rana Nov 22 '18 at 14:13
  • where would i get that block id from. also where did you get the 17 from? – theSeeker Nov 22 '18 at 14:35
  • When you create static block, you must have id – Sohel Rana Nov 22 '18 at 16:26

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.