Solution for Matrix-within-Matrix (or More Robust Table Fields) I was wondering if anyone has stumbled on a good solution for including matrix-like fields within a matrix block. I’m working on a site where each page's is constructed in one big matrix with several block types (each representing a “row" in the page) like…


Introduction
Stats
Quotes
Bios
etc.


Blocks like Stats, Quotes, etc. can hold either just one, or several of these items, so right now the subfields look something like this:


Block Title
Stat 1: Number
Stat 1: Text
Stat 2: Number
Stat 2: Text …etc. up to Stat 6


Rather than having all these fields in view by default, it would (obviously) be best if the user were just adding Stats as rows in an inner table or Matrix. Initially I thought that using Table fields would be the fix, but in several cases I need to include fields that aren’t natively supported in in Tables (like Assets, Rich Text, etc.). 

At the very least it would be nice to collapse some of the fields that are likely not going to be needed so they are out of the way (so in the example above, maybe show fields for the first 2 stats, hide field for the next 4).

Has anybody stumbled on a good solution (maybe a Plugin) for either allowing more field types within Tables, adding a Matrix to a Matrix block, or collapsing fields by default?

Also open to other suggestions … seems like a lot of sites take this “stacked rows” approach, so guessing I’m not alone here. Thanks!
Rather than trying to store multiple stats together in a single block, another option would be to make a "Stat" (singular) block type, which only holds a single stat, and just have authors create as many of those as they need, positioned together.

From your template, when looping through blocks, you can check to see if the current block is the first/last of its type, and add some extra HTML when that's the case, so that consecutive Stat blocks still appear grouped together in the rendered HTML. Something like this:

{% for block in entry.myMatrixField %}

    {# Find out if this is the first/last consecutive block of this
type #}
    {% set type = block.type.handle %}
    {% set isFirstConsecutiveBlockOfType = (loop.first or type != block.getPrev().type.handle) %}
    {% set isLastConsecutiveBlockOfType = (loop.last or type != block.getNext().type.handle) %}

    {% switch type %}

        {% case 'stat' %}

            {% if isFirstConsecutiveBlockOfType %}
                &lt;div class="stats"&gt;
            {% endif %}

            &lt;!-- Stat block HTML --&gt;

            {% if isLastConsecutiveBlockOfType %}
                &lt;/div&gt;
            {% endif %}

        {% case 'quote' %}

            {% if isFirstConsecutiveBlockOfType %}
                &lt;div class="quotes"&gt;
            {% endif %}

            &lt;!-- Quote block HTML --&gt;

            {% if isLastConsecutiveBlockOfType %}
                &lt;/div&gt;
            {% endif %}

    {% endswitch %}
{% endfor %}