How can I conditionally override a TWIG layout block?

Blocks don't care about any logic around it, as said in the documentation:

A block provides a way to change how a certain part of a template is rendered but it does not interfere in any way with the logic around it.

You should put that logic inside the block, not on the outerside, as you can see on the last example in that article.


Define

{% block footer %}Some standard content{% endblock %}

in parent twig template. Then in template where you want to decide if display content of footer you can do:

{% block footer %}
  {% if not modal == true %}
    {{ parent() }}
  {% endif %}
{% endblock %}

If the modal is true - footer will be empty, if not - in footer will be printed "Some standard content"