By Prestosaurus


2019-04-12 03:16:48 8 Comments

Having trouble seeing why my regions render when I think they shouldn't...

page.html.twig:

{% if page.region %}
  {{ page.region }}
{% endif %}

region.html.twig:

{% if content %}
  <div id="" aria-label="" role="" {{ attributes.addClass(region_classes) }}>
    {{ content }}
  </div>
{% endif %}

block.html.twig:

{% if content %}
<div{{ attributes.addClass(block_classes) }}>

  {# Label. If not displayed, we still provide it for screen readers. #}
  {% if not configuration.label_display %}
    {% set title_attributes = title_attributes.addClass('visually-hidden') %}
  {% endif %}
  {{ title_prefix }}
  <h2{{ title_attributes.setAttribute('id', heading_id) }}>{{ configuration.label }}</h2>
  {{ title_suffix }}

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

</div>
{% endif %}

block--system-messages-block.html.twig:

{% extends "block.html.twig" %}

{% block content %}
{{ content }}
{% endblock %}

I believe it has to do with my extended block templates. These seem to be the ones that will still render even when there is "no" content.

What am I missing? If I use an if check around {% block content %} Twig throws an exception, inside there is no effect.

Adding |render|striptags|trim|length > 0 in any of these templates doesn't seem to solve the issue, and in some cases, forms and Drupal messages don't validate (so nothing returns when it should).

0 comments

Related Questions

Sponsored Content

1 Answered Questions

2 Answered Questions

[SOLVED] How to assign blocks to particular regions on theme install?

0 Answered Questions

Remove all generated HTML for blocks/regions

  • 2017-04-30 06:29:42
  • George Katsanos
  • 71 View
  • 0 Score
  • 0 Answer
  • Tags:   theming blocks

2 Answered Questions

[SOLVED] Render Array Customise Theming

  • 2017-01-12 21:10:49
  • Mo-ster
  • 616 View
  • 2 Score
  • 2 Answer
  • Tags:   theming 8

3 Answered Questions

[SOLVED] Using blocks in multiple regions

  • 2016-04-28 11:52:36
  • parth.k
  • 60 View
  • 2 Score
  • 3 Answer
  • Tags:   blocks

1 Answered Questions

Are regions and features automatically created when creating a sub subtheme?

  • 2015-12-12 18:18:14
  • user54721
  • 45 View
  • 1 Score
  • 1 Answer
  • Tags:   theming regions

2 Answered Questions

Regions are gone

  • 2013-02-21 14:08:12
  • Michiel
  • 110 View
  • 2 Score
  • 2 Answer
  • Tags:   7 theming regions

0 Answered Questions

1 Answered Questions

[SOLVED] Trouble hooking blocks with theme templates

  • 2012-04-24 22:19:47
  • A_funs
  • 43 View
  • 0 Score
  • 1 Answer
  • Tags:   theming blocks

3 Answered Questions

[SOLVED] Regions. how can I disable a region? (not disabling blocks)

  • 2011-08-11 00:51:37
  • cigotete
  • 3555 View
  • 3 Score
  • 3 Answer
  • Tags:   6 blocks regions

Sponsored Content