Setting body ID from includes does not work This is my _layouts/main.twig:

&lt;body {% if bodyId is defined %}id="{{ bodyId }}"{% endif %}&gt;

  {% include '_layouts/header.twig' %}

  {% block main %}

  {% endblock %}

&lt;/body&gt;


Then i have blog/_entry.twig with:  

{% extends '_layouts/main' %}

{% block main %}

{% switch entry.entryType.entryIs.value %}
    {% case 'listing' %}
        {% include 'blog/_listing.twig' %}
    {% case 'listingSimple' %}
        {% include 'blog/_listing-simple.twig' %}
    {% case 'article' %}
        {% include 'blog/_single-entry.twig' %}
{% endswitch %}

{% endblock %}


If I do:

{% set bodyId = 'article' %}


in my blog/_single-entry.twig that does not work.  

But it works if i set bodyId in my index.twig in the root that is not a include.
So Twig has a particular processing order for things like variables, includes, extends and all that sort of stuff. Basically, you can't set a variable in an included template and then use that in an extended template.

Here's a great article that goes into this topic in a little more depth: https://nystudio107.com/blog/twig-processing-order-and-scope - I'd highly recommend you give it a read.