cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a custom footer using static blocks, XML layout and templates?

SOLVED

How to create a custom footer using static blocks, XML layout and templates?

I am trying to build a custom design for a footer, and am trying to figure out how to go about this correctly.

 

My footer will have three columns of links on the left, a column with text on the right, and across the bottom an area for copyright info - each needs to be editable via the admin section of the site.

 

Using the layout.xml for Magento_Theme, I've figured out how to create the container and its html tags, and using a static block I can fill it with content. My problem is that at the moment I'm placing ALL of the HTML to create the footer which I'm pretty sure is poor practice.

 

What I believe I should be doing is to create my container for my footer, then create blocks for each column of links, a block for the text info, and a block for the copyright info. But I need each of these wrapped in my own html tags, so I believe the way to achieve that is by calling a template?  Then each content block needs to be editable via static blocks from the admin.

 

I can't find any clear documentation (that I understand) to do this. I have assumed that I need to do the following:

  • Create a container for my custom footer via XML
  • Create Blocks inside that container that each call a template (so I can define the html that wraps it and style them)
  • On Magento create the static blocks
  • From the templates call the each static block

Firstly, is this the correct way to go about this?
If it is can anyone point me to some clear documentation or tell me how to achieve this?

Any help appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to create a custom footer using static blocks, XML layout and templates?

Ok I've figured this out.

To display CMS block content in template I need this

<?php
echo $this->getLayout()
->createBlock('Magento\Cms\Block\Block')
->setBlockId('your_block_ID')
->toHtml();
?>

for each editable block of content, and then in the layout.xml file for Magento_Theme I've created a container and inside that a block that calls my template which has the above code used multiple times, once for every block I need to display.

 

<container name="footer.container.custom" as="containerFooter" label="Custom Footer" htmlTag="div" htmlClass="site-footer"> 
<block class="Magento\Framework\View\Element\Template" name="footer.content" template="Magento_Theme::footer-content.phtml" />
</container>

View solution in original post

1 REPLY 1

Re: How to create a custom footer using static blocks, XML layout and templates?

Ok I've figured this out.

To display CMS block content in template I need this

<?php
echo $this->getLayout()
->createBlock('Magento\Cms\Block\Block')
->setBlockId('your_block_ID')
->toHtml();
?>

for each editable block of content, and then in the layout.xml file for Magento_Theme I've created a container and inside that a block that calls my template which has the above code used multiple times, once for every block I need to display.

 

<container name="footer.container.custom" as="containerFooter" label="Custom Footer" htmlTag="div" htmlClass="site-footer"> 
<block class="Magento\Framework\View\Element\Template" name="footer.content" template="Magento_Theme::footer-content.phtml" />
</container>

View solution in original post