<p>According to the documentation, I just have to pass the matrix fields handle <code>block</code> instead of <code>block.tabEntry</code>. Craft will automatically look for a relationship field (how smart). If you have multiple relation fields, you have to  use the dot notation with the field name. (→ see <a href="https://craftcms.com/docs/relations" rel="nofollow">Relations – Going Through Matrix</a>)</p>

<p>I still don't understand why using the dot notation would break it, but it apparently does. I checked my field name several times. Anywho, thanks for the help all! </p>

<pre><code>{% for block in entry.contentMatrix %}

  {# Tabs Block Type #}
  {% if block.type == "tabs" %}
  {% set entries = craft.entries.relatedTo(block) %}

    {% for entry in entries %}
      {# Matrix Content #}
      {% for block in entry.tabsMatrix.type('videoChannel, videoPlayer, copy') %}
        {{ block.title }}
      {% endfor %}
    {% endfor %}
  {% endif %}

{% endfor %}
</code></pre>

CC BY-SA 3.0
2016-01-27T16:09:04.003Z
2016-01-27T17:20:55.173Z
2016-01-27T17:20:55.173Z
Ben Shoults
<p>Do you need to <a href="https://craftcms.com/docs/matrix-fields#filtering-by-block-type" rel="nofollow">filter by block type</a>?</p>

<p>Maybe something like this:</p>

<pre><code>{% for block in entry.contentMatrix %}

    {# Tabs Block Type #}
    {% if block.type == "tabs" %}

        {% set entries = craft.entries.relatedTo(block.tabEntry) %}

        {% for entry in entries %}
            {# Matrix Content #}
            {% for content in entry.tabsMatrix.type('videoChannel, videoPlayer, copy') %}

                {% if content.type == "videoChannel" %}
                    {{ content.title }}
                {% elseif content.type == "videoPlayer" %}
                    {{ content.url }}
                {% else %}
                    {{ content.text }}
                {% endif %}

            {% endfor %}

        {% endfor %}

    {% endif %}

{% endfor %}
</code></pre>

<p>Note: Matrix Content vars (*.title, *url, *text) are just examples.</p>

CC BY-SA 3.0
2016-01-27T16:04:13.377Z
My understanding is that we can add type to the `for` to choose multiple matrix types.
Ben Shoults
CC BY-SA 3.0
2016-01-26T23:26:03.113Z
2016-01-26T23:26:03.113Z
Natetronn
<p>I have a matrix field with an entries field which ties into another matrix field. Is this possible? Here's what I have so far...</p>

<pre><code>{% for block in entry.contentMatrix %}

  {# Tabs Block Type #}
  {% if block.type == "tabs" %}
    {% set entries = craft.entries.relatedTo(block.tabEntry) %}

    {% for entry in entries %}
      {# Matrix Content #}
      {% for block in entry.tabsMatrix.type('videoChannel, videoPlayer, copy') %}
        {{ block.title }}
      {% endfor %}
    {% endfor %}
  {% endif %}

{% endfor %}
</code></pre>

<p>This does not produce an error, just nothing.</p>

CC BY-SA 3.0
2016-01-26T22:34:58.253Z
As an aside, is the `switch` tag better suited than the conditional for looping through the block types? Is there a performance difference?
Ben Shoults
CC BY-SA 3.0
2016-01-26T23:14:19.520Z
No performance difference in conditional vs switch. Switch is just a bit cleaner sometimes.
Douglas McDonald
CC BY-SA 3.0
2016-01-26T23:27:20.667Z
Your code looks ok to me. You might want to dump variables (or test length) within each loop to see if your getting results. i.e. `{{ dump(entries) }}` or `{{ entries|length }}`
Douglas McDonald
CC BY-SA 3.0
2016-01-27T16:10:38.997Z
The dump helped me realize that nothing was getting passed before getting to the matrix loop...thanks
Ben Shoults
<entries><matrix>
Is Matrix > Entries > Matrix possible?
# Is Matrix > Entries > Matrix possible?

(Asked by: username_0 on 2016-01-26)

I have a matrix field with an entries field which ties into another matrix field. Is this possible? Here's what I have so far...
{% for block in entry.contentMatrix %}

  {# Tabs Block Type #}
  {% if block.type == "tabs" %}
    {% set entries = craft.entries.relatedTo(block.tabEntry) %}

    {% for entry in entries %}
      {# Matrix Content #}
      {% for block in entry.tabsMatrix.type('videoChannel, videoPlayer, copy') %}
        {{ block.title }}
      {% endfor %}
    {% endfor %}
  {% endif %}

{% endfor %}

This does not produce an error, just nothing.

**Tags:** entries, matrix

> **Comments:**
> **username_0**: As an aside, is the `switch` tag better suited than the conditional for looping through the block types? Is there a performance difference?  
> **username_1**: No performance difference in conditional vs switch. Switch is just a bit cleaner sometimes.  
> **username_1**: Your code looks ok to me. You might want to dump variables (or test length) within each loop to see if your getting results. i.e. `{{ dump(entries) }}` or `{{ entries|length }}`  
> **username_0**: The dump helped me realize that nothing was getting passed before getting to the matrix loop...thanks  

---

## 2 answers

### Answer by username_0 on 2016-01-27. Score: 1 | Accepted answer

According to the documentation, I just have to pass the matrix fields handle block instead of block.tabEntry. Craft will automatically look for a relationship field (how smart). If you have multiple relation fields, you have to  use the dot notation with the field name. (→ see Relations – Going Through Matrix)
I still don't understand why using the dot notation would break it, but it apparently does. I checked my field name several times. Anywho, thanks for the help all! 
{% for block in entry.contentMatrix %}

  {# Tabs Block Type #}
  {% if block.type == "tabs" %}
  {% set entries = craft.entries.relatedTo(block) %}

    {% for entry in entries %}
      {# Matrix Content #}
      {% for block in entry.tabsMatrix.type('videoChannel, videoPlayer, copy') %}
        {{ block.title }}
      {% endfor %}
    {% endfor %}
  {% endif %}

{% endfor %}


---

### Answer by username_2 on 2016-01-26. Score: 1

Do you need to filter by block type?
Maybe something like this:
{% for block in entry.contentMatrix %}

    {# Tabs Block Type #}
    {% if block.type == "tabs" %}

        {% set entries = craft.entries.relatedTo(block.tabEntry) %}

        {% for entry in entries %}
            {# Matrix Content #}
            {% for content in entry.tabsMatrix.type('videoChannel, videoPlayer, copy') %}

                {% if content.type == "videoChannel" %}
                    {{ content.title }}
                {% elseif content.type == "videoPlayer" %}
                    {{ content.url }}
                {% else %}
                    {{ content.text }}
                {% endif %}

            {% endfor %}

        {% endfor %}

    {% endif %}

{% endfor %}

Note: Matrix Content vars (*.title, *url, *text) are just examples.

> **Comments:**
> **username_0**: My understanding is that we can add type to the `for` to choose multiple matrix types.  

---

