Adding a Callout block

We will take advantage of the Before Content region we created in our theme's configuration file to add our next component. The Callout block we identified in our mockup earlier allows us to add additional information that helps introduce our Contact form.

If we quickly review the contact.html page from the Mockup folder, we can identify that we will need to create a custom block that consists of a heading and a paragraph.

Adding a Callout block

This is a pretty simple block to create, so let's get started by navigating to /admin/structure/block, which will take us to the Block layout admin.

Next, we will follow these steps:

  1. Click on the Place block button in the Before Content region.
  2. Click on the Add custom block button.
  3. Enter a Block description of Contact Callout.
  4. Select HTML No Editor from the Text format dropdown.
  5. Add the markup located in the Chatper10/start/content/ContactCallout.txt file to the Body field, as shown in the following image:
    Adding a Callout block
  6. Click on the Save button to proceed to the Configure block screen.
  7. Uncheck the Display title checkbox.
  8. Select the Pages vertical tab within the Visibility section.
  9. Enter a value of /contact in the Pages text area.
  10. Choose Show for the listed pages under Negate the condition.
  11. Choose Before Content from the Region field.
  12. Click on the Save block button.

We now have our Contact Callout block created and assigned to our Before Content region. Let's make sure that our new block is displaying correctly by navigating back to our Contact page.

Adding a Callout block

Therefore, our content is displaying in the correct region but not quite visually what we were expecting. However, like any other block, we can remedy this by creating a Twig template and apply any additional markup or classes that may be needed.

Creating the Callout block template

Using the FILE NAME SUGGESTIONS, we can navigate to the core/modules/block/templates folder and copy the block.html.twig template to our themes/octo/templates folder. Next, we will need to rename the template to block--contactcallout.html.twig and then replace the markup with the following:

New markup

{% set classes = ['block','contact-intro'] %}

<div{{ attributes.addClass(classes) }}>
  <div class="container">
    {{ title_prefix }}
    {% if label %}
    <h4{{ title_attributes }}>{{ label }}</h4>
    {% endif %}
    {{ title_suffix }}
    {% block content %}
    {{ content }}
    {% endblock %}
  </div>
</div>

Make sure to save the template, clear Drupal's cache, and refresh the Contact page in the browser. Our block should now look exactly like our mockup. Now we will move on to our next component, which involves integrating Google Maps.

..................Content has been hidden....................

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