Send a block... into a block? I'm fiddling around with Twig and CraftCMS, trying to create a component-based structure... of sorts.

All good so far, except this one thing I got stuck on.


Here's an excerpt from my main layout:

&lt;body&gt;
    {% include 'components/header.twig' %}

    {% block content %}
        woops...
    {% endblock %}

    {% include 'components/footer.twig' %}
&lt;/body&gt;


Which currently works.

But, I'd like to do something like this...

&lt;body&gt;
    {% include 'components/header.twig' %}
    {% include 'components/main-wrapper.twig' %}
    {% include 'components/footer.twig' %}
&lt;/body&gt;


Where the main-wrapper.twig is like this, for example:

&lt;main class="main"&gt;
    {% block content %}
        woops... 
    {% endblock %}
&lt;/main&gt;


But it does not work. "woops..." from main-wrapper.twig is displayed.



I've tried a different route without success as well: 

&lt;body&gt;
    {% include 'components/header.twig' %}

    {% embed 'components/main-wrapper.twig' %}
        {% block children %}
            {# I want to have the block content here... #}
        {% endblock %}
    {% endembed %}

    {% include 'components/footer.twig' %}
&lt;/body&gt;


Where the main-wrapper.twig has a block named children instead... but no dice.



It does appear that what I'm trying to do is not possible, which is why I'm asking here as a last resort :)


EDIT:

For those interested, here's what I ended up with, stripped for clarity:

{# default.twig - default layout #}

&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
       ...
    &lt;/head&gt;
    &lt;body&gt;
        {% include 'components/header.twig' %}
        {% block wrappedContent %}{% endblock %}
        {% include 'components/footer.twig' %}
    &lt;/body&gt;
&lt;/html&gt;




{# regular.twig - base page referred in the admin panel #}

{% extends "components/main.twig" %}

{% block content %}
    --- stuff for a page ---
{% endblock %}




{# main.twig - wrapper component! :D #}

{% extends "layouts/default.twig" %}

{% block wrappedContent %}
    &lt;main class="main"&gt;
        &lt;div class="main__wrapper"&gt;
            {% block content %}
                wooops...
            {% endblock %}
        &lt;/div&gt;
    &lt;/main&gt;
{% endblock %}
It seems to be what you need is Twigs extend functionality. What you have here is a very common template structure so there is nothing out of the ordinary!

Firstly, going from your code I'd recommend your main layout template file looks something like this. The idea here being that these elements will not change for each page, but the content or information displayed inside them will. This template file is where you would also load in your CSS, Javascript etc.

&lt;body&gt;
    {% include 'components/header' %}

    &lt;main class="main"&gt;
        {% block content %}{% endblock %}
    &lt;/main&gt;

    {% include 'components/footer' %}
&lt;/body&gt;


Say you have a page that will sit on www.yoursite.co.uk/about. You could create a template file in your templates folder called about.twig, and to use your base template file it would look something like this:

{% extends "path/to/main/layout" %}

{% block content %}

    &lt;p&gt;The content for your about page&lt;/p&gt;

{% endblock %}


Hope that clears it up for you!