<p>If you look at how Craft handles <a href="https://craftcms.com/docs/routing" rel="nofollow noreferrer">routing</a> you will see this:</p>

<blockquote>
  <p>If the URI matches an entry’s or category’s URI, the section’s/category group’s template will get loaded, and the matched element will be made available to the template via a pre-populated <code>entry</code> or <code>category</code> variable.</p>
</blockquote>

<p>So Craft is assigning that <code>entry</code> variable that you are referencing on line 1 of your code. Then on line 3, you do <code>{% set entry = block.sideLink.first() %}</code> which overwrites that initial <code>entry</code> variable with this new value, which is why the second matrix disappears.</p>

<p>What you probably want to do is this:</p>

<pre><code>{% for block in entry.sideMenu %}
  {% if block.type == "sideMenuItem" %}
    {% set sideLinkEntry = block.sideLink.first() %}
    {% if sideLinkEntry %}
       &lt;a href="{{ sideLinkEntry.url }}"&gt;{{ block.sideTitle }}&lt;/a&gt;
    {% endif %}
  {% endif %}
{% endfor %}
</code></pre>

<p>And your original <code>entry</code> will be unmodified.</p>

CC BY-SA 3.0
2017-10-04T19:30:20.583Z
Oh hells yeah that worked! Thanks so much, i can finally move on with my life!
kingkelly
CC BY-SA 3.0
2017-10-04T23:51:10.697Z
Glad I could help! Hope I managed to make the whole thing a bit less mysterious
Marion Newlevant
CC BY-SA 3.0
2017-10-04T04:33:29.620Z
2017-10-04T04:33:29.620Z
Marion Newlevant
<p>I'm having a bit of difficulty having 2 different matrix blocks show on one page, and they both have Entries fields. As soon as I put <code>{% set entry</code> for my first Matrix, the second Matrix disappears.</p>

<pre><code>{% for block in entry.sideMenu %}
 {% if block.type == "sideMenuItem" %}
    {% set entry = block.sideLink.first() %}
      {% if entry %}
         &lt;a href="{{ entry.url }}"&gt;{{ block.sideTitle }}&lt;/a&gt;
      {% endif %}
 {% endif %}
{% endfor %}
</code></pre>

<entries><matrix>
Multiple Matrix blocks on one page
# Multiple Matrix blocks on one page

(Asked by: username_0 on 2017-10-04)

I'm having a bit of difficulty having 2 different matrix blocks show on one page, and they both have Entries fields. As soon as I put {% set entry for my first Matrix, the second Matrix disappears.
{% for block in entry.sideMenu %}
 {% if block.type == "sideMenuItem" %}
    {% set entry = block.sideLink.first() %}
      {% if entry %}
         {{ block.sideTitle }}
      {% endif %}
 {% endif %}
{% endfor %}

**Tags:** entries, matrix


---

## 1 answers

### Answer by username_1 on 2017-10-04. Score: 1 | Accepted answer

If you look at how Craft handles routing you will see this:

If the URI matches an entry’s or category’s URI, the section’s/category group’s template will get loaded, and the matched element will be made available to the template via a pre-populated entry or category variable.

So Craft is assigning that entry variable that you are referencing on line 1 of your code. Then on line 3, you do {% set entry = block.sideLink.first() %} which overwrites that initial entry variable with this new value, which is why the second matrix disappears.
What you probably want to do is this:
{% for block in entry.sideMenu %}
  {% if block.type == "sideMenuItem" %}
    {% set sideLinkEntry = block.sideLink.first() %}
    {% if sideLinkEntry %}
       {{ block.sideTitle }}
    {% endif %}
  {% endif %}
{% endfor %}

And your original entry will be unmodified.

> **Comments:**
> **username_0**: Oh hells yeah that worked! Thanks so much, i can finally move on with my life!  
> **username_1**: Glad I could help! Hope I managed to make the whole thing a bit less mysterious  

---

