Right, you can't define the same block multiple times, even if they are in separate logical branches.
These both work:
{% if show is defined %}
{% block heading %}
{% if show == 'add_form' %}
Add
{% elseif show == 'main' %}
Main
{% endif %}
{% endblock %}
{% endif %}
{% block heading %}
{% if show is defined %}
{% if show == 'add_form' %}
Add
{% elseif show == 'main' %}
Main
{% endif %}
{% endif %}
{% endblock %}
I think the second one is clearer (at least in this case), because a template that extends another one cannot include contents outside Twig blocks. What this means is that if you try to do something like this:
{% extends 'layout.twig' %}
{% block heading %}
Some content
{% endblock %}
Hello world!
You'll get a Twig_Error_Syntax
exception with this message:
A template that extends another one cannot include contents outside Twig blocks. Did you forget to put the contents inside a
{% block %}
tag?
So, the template stays clear if you put all code inside blocks.