Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-04T19:30:20.583Z
Answers.Text: Oh hells yeah that worked! Thanks so much, i can finally move on with my life!
Answers.UserDisplayName: kingkelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-04T23:51:10.697Z
Answers.Text: Glad I could help! Hope I managed to make the whole thing a bit less mysterious
Answers.UserDisplayName: Marion Newlevant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-04T04:33:29.620Z
Answers.LastActivityDate: 2017-10-04T04:33:29.620Z
Answers.UserDisplayName: Marion Newlevant
Body: <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>
  
Tags: <entries><matrix>
Title: Multiple Matrix blocks on one page
ThreadText: # 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 %}
           <a href="{{ entry.url }}">{{ block.sideTitle }}</a>
        {% 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](https://craftcms.com/docs/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 %}
         <a href="{{ sideLinkEntry.url }}">{{ block.sideTitle }}</a>
      {% 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  
  
  ---
  
  