Answers.Body: <p>Here's how I would approach this...</p>
  <pre><code>{% set classBlocks = entry.classBlocks.all() %}
  
  {% if classBlocks | length %}
      {% set instructors = classBlocks | filter(block =&gt; block.type == 'instructors') %}
      by &lt;strong&gt;{{ instructors | map(instructor =&gt; instructor.fullName) | join(', ', ', and ') }}&lt;/strong&gt;
  {% endif %}
  </code></pre>
  <p>We're using several filters here to achieve what I think you're trying to achieve:</p>
  <ul>
  <li><a href="https://twig.symfony.com/doc/2.x/filters/filter.html" rel="nofollow noreferrer"><code>| filter</code></a> is used to filter just the instructor blocks out of all your class blocks; this saves us from having to do the cloning and extra query mess and is more performant.</li>
  <li><a href="https://twig.symfony.com/doc/2.x/filters/map.html" rel="nofollow noreferrer"><code>| map</code></a> is used to take our array of instructor blocks and return an array containing just their names.</li>
  <li><a href="https://twig.symfony.com/doc/2.x/filters/join.html" rel="nofollow noreferrer"><code>| join</code></a> is used to take the array of names and create a nice readable list (I find it cleaner than doing the loop checking like you're doing) - e.g. &quot;Bob, Matt, and Susy&quot;</li>
  </ul>
  <p>Let me know in the comments if you have any questions or if I'm not understanding the question correctly!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-04T16:34:22.257Z
Answers.Text: Ok so first of all thank you.
  
  It didn't work. Same think is happening that i've gotten before. nothing but "by" is output and if I add `{{instructors|join(' | ')}}` to see what's in the instructors array I get the ID of the entry field in the matrix type. This seems to be a bug with craft. The documentation is either incorrect or this is a bug.
Answers.UserDisplayName: jpwdesigns
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-04T16:53:38.773Z
Answers.Text: If I do this:
  ```
  {% if classBlocks | length %}
      {% set instructors = classBlocks | filter(block => block.type == 'instructors') %}
        {% for instructor in instructors %} {{ instructor.instructorEntries|join(' | ') }}
      {% endfor %}
  {% endif %}
  ```
  
  I get the title's of the entries I want. Nice right? However I want the fullName field of those entries
Answers.UserDisplayName: jpwdesigns
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-04T17:14:09.793Z
Answers.Text: If I try to step in to access the fullName field of the entry, I get a date time error. craft Object of class DateTime could not be converted to string. That just makes no sense at all. I've given up and approached this differently.
Answers.UserDisplayName: jpwdesigns
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-04T04:01:05.307Z
Answers.LastActivityDate: 2020-09-04T04:01:05.307Z
Answers.UserDisplayName: Jalen Davenport
Body: <p>I have a matrix field with with multiple types. In a template I want to loop through all of the entries of that matrix field as you normally would. However, I also want to access a bit of data from a specific type and I can not figure out how to do it. Very frustrating. Definitely would have been a no brainer to do in craft 2.5.</p>
  <p>The matrix field has a type of &quot;Instructor&quot; which is an entry type. The entry has a field of &quot;FullName&quot;.</p>
  <p>So I want to say, if there is an entry type of Instructors in the matrix field, then output the full name of each entry selected in the matrix field of type &quot;Instructor&quot;.</p>
  <p>I've tried various methods based on the matrix blocks documentation and nothing works. The closest I get is the ID of the matrix field entry. Here is one example that should explain what I'm attempting to do.</p>
  <pre><code>  {% set classBlocks = entry.classBlocks %}
    {% if classBlocks|length %}
      {% set instructors = clone(classBlocks).type('instructors').all() %}
      by &lt;strong&gt;
        {% for instructor in instructors %}
          {% if not loop.first %}, {% endif %}
          {{ instructor.fullName }}
        {% endfor %}
      &lt;/strong&gt;
    {% endif %}
  </code></pre>
  <p>Is this even possible? Seems pretty simple. At least in craft 2.5 I could have just looped through the matrix field and if the type was 'instructors' loop through the instructor entries outputting their full name.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-09-06T10:15:19.763Z
Comments.Text: Everything is _possible_, but the wording of your question makes it difficult to understand your setup, as you are using the phrase "entry type" when you could mean "block type", or possibly "field type". These are three separate things. Matrix blocks cannot contain "entry types". Consider editing your question for clarity between block type handles and field handles.
Comments.UserDisplayName: James Smith
Tags: <templating><matrix>
Title: Output of matrix field twice in one template
ThreadText: # Output of matrix field twice in one template
  
  (Asked by: username_0 on 2020-09-04)
  
  I have a matrix field with with multiple types. In a template I want to loop through all of the entries of that matrix field as you normally would. However, I also want to access a bit of data from a specific type and I can not figure out how to do it. Very frustrating. Definitely would have been a no brainer to do in craft 2.5.
  
  The matrix field has a type of "Instructor" which is an entry type. The entry has a field of "FullName".
  
  So I want to say, if there is an entry type of Instructors in the matrix field, then output the full name of each entry selected in the matrix field of type "Instructor".
  
  I've tried various methods based on the matrix blocks documentation and nothing works. The closest I get is the ID of the matrix field entry. Here is one example that should explain what I'm attempting to do.
  
  ```
    {% set classBlocks = entry.classBlocks %}
    {% if classBlocks|length %}
      {% set instructors = clone(classBlocks).type('instructors').all() %}
      by <strong>
        {% for instructor in instructors %}
          {% if not loop.first %}, {% endif %}
          {{ instructor.fullName }}
        {% endfor %}
      </strong>
    {% endif %}
  
  ```
  
  Is this even possible? Seems pretty simple. At least in craft 2.5 I could have just looped through the matrix field and if the type was 'instructors' loop through the instructor entries outputting their full name.
  
  **Tags:** templating, matrix
  
  > **Comments:**
  > **username_1**: Everything is _possible_, but the wording of your question makes it difficult to understand your setup, as you are using the phrase "entry type" when you could mean "block type", or possibly "field type". These are three separate things. Matrix blocks cannot contain "entry types". Consider editing your question for clarity between block type handles and field handles.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-09-04. Score: 1
  
  Here's how I would approach this...
  
  ```
  {% set classBlocks = entry.classBlocks.all() %}
  
  {% if classBlocks | length %}
      {% set instructors = classBlocks | filter(block => block.type == 'instructors') %}
      by <strong>{{ instructors | map(instructor => instructor.fullName) | join(', ', ', and ') }}</strong>
  {% endif %}
  
  ```
  
  We're using several filters here to achieve what I think you're trying to achieve:
  
  * [`| filter`](https://twig.symfony.com/doc/2.x/filters/filter.html) is used to filter just the instructor blocks out of all your class blocks; this saves us from having to do the cloning and extra query mess and is more performant.
  * [`| map`](https://twig.symfony.com/doc/2.x/filters/map.html) is used to take our array of instructor blocks and return an array containing just their names.
  * [`| join`](https://twig.symfony.com/doc/2.x/filters/join.html) is used to take the array of names and create a nice readable list (I find it cleaner than doing the loop checking like you're doing) - e.g. "Bob, Matt, and Susy"
  
  Let me know in the comments if you have any questions or if I'm not understanding the question correctly!
  
  > **Comments:**
  > **username_0**: Ok so first of all thank you.  It didn't work. Same think is happening that i've gotten before. nothing but "by" is output and if I add `{{instructors|join(' | ')}}` to see what's in the instructors array I get the ID of the entry field in the matrix type. This seems to be a bug with craft. The documentation is either incorrect or this is a bug.  
  > **username_0**: If I do this: ``` {% if classBlocks | length %}     {% set instructors = classBlocks | filter(block => block.type == 'instructors') %}       {% for instructor in instructors %} {{ instructor.instructorEntries|join(' | ') }}     {% endfor %} {% endif %} ```  I get the title's of the entries I want. Nice right? However I want the fullName field of those entries  
  > **username_0**: If I try to step in to access the fullName field of the entry, I get a date time error. craft Object of class DateTime could not be converted to string. That just makes no sense at all. I've given up and approached this differently.  
  
  ---
  
  