Implementing the footer

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:

  1. First, we will need to create five custom blocks for our Newsletter, About Us, Contact Us, Copyright, and Social Icons content. Once the blocks are created, they will need to be assigned to their respective regions.
  2. Finally, we will need to refactor the markup in our footer to accommodate the various Twig variables to print out each region.

Creating our custom blocks

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:

  1. Click on the Place block button in the Footer first region.
  2. Click on the Add custom block button.
  3. Enter a Block description of Newsletter.
  4. Select HTML No Editor from the Text format dropdown.
  5. Add the markup located in the Chatper06/start/content/Newsletter.txt file to the Body field.
  6. Click on the Save button to proceed to the Configure block screen.
  7. Choose Footer first from the Region field.
  8. Click on the Save block button.

About Us block:

  1. Click on the Place block button in the Footer second region.
  2. Click on the Add custom block button.
  3. Enter a Block description of About Us.
  4. Select HTML No Editor from the Text format dropdown.
  5. Add the markup located in the Chatper06/start/content/AboutUs.txt file to the Body field.
  6. Click on the Save button to proceed to the Configure block screen.
  7. Choose Footer second from the Region field.
  8. Click on the Save block button.

Footer Contact block:

  1. Click on the Place block button in the Footer third region.
  2. Click on the Add custom block button.
  3. Enter a Block description of Footer Contact.
  4. Select HTML No Editor from the Text format dropdown.
  5. Add the markup located in the Chatper06/start/content/FooterContact.txt file to the Body field.
  6. Click on the Save button to proceed to the Configure block screen.
  7. Enter a title of Contact Us in the Title field.
  8. Choose Footer third from the Region field.
  9. Click on the Save block button.

Copyright block:

  1. Click on the Place block button in the Footer Bottom Left region.
  2. Click on the Add custom block button.
  3. Enter a Block description of copyright.
  4. Select HTML No Editor from the Text format dropdown.
  5. Add the markup located in the Chatper06/start/content/Copyright.txt file to the Body field.
  6. Click on the Save button to proceed to the Configure block screen.
  7. Uncheck the Display title checkbox.
  8. Choose Footer Bottom Left from the Region field.
  9. Click on the Save block button.

Social Icons block:

  1. Click on the Place block button in the Footer Bottom Right region.
  2. Click on the Place block button next to the Social Icons block. We don't need to recreate this block since blocks are now reusable.
  3. Uncheck the Display title checkbox.
  4. Footer Bottom Right should already be selected for us from the Region field.
  5. Click on the Save block button.

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.

Refactoring our main footer

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.

Footer first

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>

Footer second

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>

Footer third

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.

Footer bottom left

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>

Footer bottom right

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:

Footer bottom right
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.144.248