Theming a Block template

In the case of our Categories block, we can begin by navigating to the core/modules/block/templates folder and following these remaining steps:

  1. Copy block.html.twig and place it into our theme/octo/templates folder.
  2. Rename block.html.twig to block--views-block--categories-block-1.html.twig based on the template's suggestions.
  3. Next, we will need to replace the current markup with the following new markup to convert the default <h2> to <h4>:

    New markup

    {% set classes = ['block'] %}
    
    <div{{ attributes.addClass(classes) }}>
      {{ title_prefix }}
    
      {% if label %}
        <h4{{ title_attributes }}>{{ label }}</h4>
      {% endif %}
    
      {{ title_suffix }}
    
      {% block content %}
        {{ content }}
      {% endblock %}
    
    </div>

Once finished, make sure to save the template, ...

Get Drupal 8: Enterprise Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.