0

I want to show the D8-based blocks in the block.html.twig file with the html tag only. However, when I entered this special split file, I created a special branch file for each block area (eg region - sagblok.html.twig), block title and content css, html codes. Unfortunately, the block titles did not appear. My code is below:

<div class="BlockTitle col-sm-text-center">{{ title_prefix }}</div>
{%if label %}
  <h5{{ title_attributes }}>{{ label }}</h5>
{% endif %}
{{ title_suffix }}</div>
{% block content }}
<div class="col-sm BlockRight">
  {{ content }}
</div>
{% endblock %}

Editor screenshot enter image description here

Sorry for my English.

I have debugged the theme, I am cleaning the cache with the "drush cr" command continually. I have copied the style files of the blocks to the folder of the theme I am developing "core / templates / stable / templates / block / block.html.twig".

The content of the "block.html.twig" file looks like this:

<div{{ attributes }}>
  {{ title_prefix }}
  {% if label %}
    <h2{{ title_attributes }}>{{ label }}</h2>
  {% endif %}
  {{ title_suffix }}
  {% block content %}
    {{ content }}
  {% endblock %}
</div>

I changed the codes in this file like this:

  {% block content %}
  <aside>
    {{ content }}
  </aside>
  {% endblock %}

then I created a twig file called "region--sagblok.html.twig" belonging to the block region, codes:

<div class="BlockTitle col-sm text-center">{{ title_prefix }}
  {% if label %}
    <h5{{ title_attributes }}>{{ label }}</h5>
  {% endif %}
  {{ title_suffix }}</div>
  {% block content %}
  <div class="col-sm BlockRight">
    {{ content }}
  </div>
  {% endblock %}

unfortunately block names do not appear in this way. but when I looked at the source code, I realized that the html codes came, but the block names did not.

1 Answer 1

1

You are supposed to put your templates into a /templates subfolder of your theme.

I'd recommend you find out how to enable debugging for Twig templates during development. Here is a how-to on DO: https://www.drupal.org/docs/8/theming/twig/debugging-twig-templates

By that you'll get template suggestions printed as HTML comments directly inside the markup of your page. It will suggest you certain file namings which then must be placed inside the /templates subdirectory of your theme.

And last but not least: Flush caches as often as possible. And find out how to disable caches completely during development. Here is another how-to on DO: https://www.drupal.org/node/2598914

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.