Our footer is a little different to what we have been implementing so far. The footer consists of multiple regions and custom blocks to easily match our mockup, and will mean us following these steps:
We will begin with creating the five custom blocks as well as assigning them to the regions they need to be placed in. This will be somewhat repetitive, but is needed in order for us to complete our footer. We will start by navigating to the Block layout page at /admin/structure/block
and following these steps.
Newsletter block:
Chatper06/start/content/Newsletter.txt
file to the Body field.About Us block:
Chatper06/start/content/AboutUs.txt
file to the Body field.Footer Contact block:
Chatper06/start/content/FooterContact.txt
file to the Body field.Copyright block:
Chatper06/start/content/Copyright.txt
file to the Body field.Social Icons block:
We have successfully added all five blocks and assigned them to their respective regions. Now we just need to refactor the markup for each region, and we should be all set.
We will be refactoring the markup for each section of our main footer by replacing the static markup with the Twig variable for each region. We should be comfortable with this process by now, so let's start.
Begin by opening page--front.html.twig
and locating the main-footer
section of our markup. Within the main footer, we will see individual sections of content for each of the blocks we just created.
Locate the following markup and replace the content between with the Twig variable that represents the page region.
Current markup
<div class="col-md-4"> ... content ... </div>
New markup
<div class="col-md-4"> {{ page.footer_first }} </div>
Locate the following markup and replace the content between with the Twig variable that represents the page region.
Current markup
<div class="col-md-4"> ... content ... </div>
New markup
<div class="col-md-4"> {{ page.footer_second }} </div>
Locate the following markup and replace the content between with the Twig variable that represents the page region.
Current markup
<div class="col-md-4"> ... content ... </div>
New markup
<div class="col-md-4"> {{ page.footer_third }} </div>
With our markup now refactored, if we look at the main-footer
section of our homepage, the complete markup should look like the following:
<div class="container main-footer"> <div class="row"> <div class="col-md-4"> {{ page.footer_first }} </div> <div class="col-md-4"> {{ page.footer_second }} </div> <div class="col-md-4"> {{ page.footer_third }} </div> </div> </div>
Make sure to save our changes and then clear Drupal's cache. If we browse our homepage, we should see our static content has been replaced with the three custom blocks.
Now, let's refactor the two remaining blocks of content by locating the footer-copyright
section of our markup. Within the footer copyright, we will see individual sections of content for the two blocks we just created.
Locate the following markup and replace the content between with the Twig variable that represents the page region.
Current markup
<div class="col-md-8"> ... content ... </div>
New markup
<div class="col-md-8"> {{ page.footer_bottom_left }} </div>
Locate the following markup and replace the content between with the Twig variable that represents the page region.
Current markup
<div class="col-md-4"> ... content ... </div>
New markup
<div class="col-md-4"> {{ page.footer_bottom_right }} </div>
With our markup now refactored, if we look at the footer-copyright
section of our homepage, the complete markup should look like the following:
<div class="footer-copyright"> <div class="container"> <div class="row"> <div class="col-md-8"> {{ page.footer_bottom_left }} </div> <div class="col-md-4"> {{ page.footer_bottom_right }} </div> </div> </div> </div>
Make sure to save our changes and then clear Drupal's cache. If we browse our homepage, we should see our static content has been replaced with the two custom blocks. Our footer is complete, and should look like the following image:
18.118.144.248