Answers.Body: <p>It might seem counter-intuitive in cases where you only have 1 <em>block type</em> (i.e. <code>quote</code>) and only a single block, but your Matrix field will always be an <em>array</em>, where the blocks (i.e. the "children" of the Matrix array) aren't directly accessible:</p>
  
  <pre><code>entry.quotation
      - block1 (quote)
      ...
  </code></pre>
  
  <p>Usually, you'll output your blocks by <em>looping</em> through the Matrix field, checking each block's type. I find that using a <code>{% switch %}</code> statement is often cleaner than an if/else:</p>
  
  <pre><code>{% for block in entry.quotation %}
  
      {% switch block.type %}
  
           {% case 'quote' %}
           &lt;blockquote&gt;
               &lt;p&gt;{{ block.quoteText }}&lt;/p&gt;
               &lt;cite&gt;{{ block.quoteBy }}&lt;/cite&gt;
               &lt;a href="{{ block.quoteUrl }}"&gt;QuoteUrl&lt;a&gt;
           &lt;/blockquote&gt;
  
      {% endswitch %}
  
  {% endfor %}
  </code></pre>
  
  <p>You can, however, opt to only output blocks of a certain type. This is done by "filtering" the Matrix field using the <code>type</code> method, and removes the need for the <code>switch</code> or if/else statement. This is convenient in cases where you know you'll only have 1 block type:</p>
  
  <pre><code>{% for quote in entry.quotation.type( 'quote' ) %}
      &lt;blockquote&gt;
           &lt;p&gt;{{ quote.quoteText }}&lt;/p&gt;
           &lt;cite&gt;{{ quote.quoteBy }}&lt;/cite&gt;
           &lt;a href="{{ quote.quoteUrl }}"&gt;QuoteUrl&lt;a&gt;
       &lt;/blockquote&gt;
  {% endfor %}
  </code></pre>
  
  <p>If you know there's only 1 block, you can even remove the loop entirely by explicitly targeting the <code>first</code> block for your filtered block type. The actual amount of code will be about the same as the above example, though:</p>
  
  <pre><code>{% set quote = entry.quotation.type( 'quote' ).first %}
  {% if quote %}
      &lt;blockquote&gt;
          &lt;p&gt;{{ quote.quoteText }}&lt;/p&gt;
          &lt;cite&gt;{{ quote.quoteBy }}&lt;/cite&gt;
          &lt;a href="{{ quote.quoteUrl }}"&gt;QuoteUrl&lt;a&gt;
      &lt;/blockquote&gt;
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-27T04:48:40.213Z
Answers.Text: I will use the {% switch %} technique in other areas of my build, thank you for that.Could you expand on your switch example and demo how to switch between text and image fields? (I have another area which has 2 Block Types: text, photo and within each is a field: text, photo. How I I have nested these is probably some of the reason I am having trouble.
Answers.UserDisplayName: Craftnoob
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-27T07:38:26.930Z
Answers.Text: @Craftnoob No problem, happy to help out. If you create a new question for your other Matrix issue w/ the 2 block types, I'll be happy to take a look :)
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-27T22:05:27.463Z
Answers.Text: Thanks @mmikkel I have asked that question [link](http://craftcms.stackexchange.com/questions/9477/how-do-you-use-a-matrix-to-toggle-between-multiple-fields-from-multiple-blocks)
Answers.UserDisplayName: Craftnoob
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-26T08:22:14.893Z
Answers.LastActivityDate: 2015-04-26T08:29:52.643Z
Answers.LastEditDate: 2015-04-26T08:29:52.643Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.Body: <p>Since matrix blocks support more than one block you generally want to loop through the blocks, then grab the fields from each block (even if there is only one block defined).</p>
  
  <pre><code>{% for block in entry.quotation %}
      {% if block.type == 'quote' %}
          &lt;blockquote&gt;
              &lt;p&gt;{{ block.quoteText }}&lt;/p&gt;
              &lt;cite&gt;{{ block.quoteBy }}&lt;/cite&gt;
              &lt;a href="{{ block.quoteUrl }}"&gt;QuoteUrl&lt;a&gt;
          &lt;/blockquote&gt;
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>Fyi... I'm using camel case in the example for all the field handles as it's the craft standard, but use whatever you use — just make sure it's actually the field 'handle' and not the field 'name'.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-26T05:35:54.253Z
Answers.LastActivityDate: 2015-04-26T05:35:54.253Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>How do you display select Fields from a Matrix Block Type when there are multiple Fields?</p>
  
  <p>I have 1 Matrix Field with Handle ‘Quotation’</p>
  
  <p>The configuration for this Matrix is as follows:</p>
  
  <p>1 Block Type with handle ‘quote’</p>
  
  <p>This Block Type has 3 plain text Fields:
  ‘Quotetext’
  ‘QuoteBy’
  ‘QuoteUrl’</p>
  
  <p>I havent been able to get any output at all from this Matrix following the documentation and into following HTML structure:</p>
  
  <pre><code>&lt;blockquote&gt;
      &lt;p&gt;Quotetext&lt;/p&gt;
      &lt;cite&gt;QuoteBy&lt;/cite&gt;
      &lt;a href="QuoteUrl"&gt;QuoteUrl&lt;a&gt;
  &lt;/blockquote&gt;
  </code></pre>
  
  <p>Can anyone help me solve this issue?
  Thank you</p>
  
Tags: <templating><matrix>
Title: How do you display select Fields from a Matrix Block Type when there are multiple Fields?
ThreadText: # How do you display select Fields from a Matrix Block Type when there are multiple Fields?
  
  (Asked by: username_0 on 2015-04-26)
  
  How do you display select Fields from a Matrix Block Type when there are multiple Fields?
  
  I have 1 Matrix Field with Handle ‘Quotation’
  
  The configuration for this Matrix is as follows:
  
  1 Block Type with handle ‘quote’
  
  This Block Type has 3 plain text Fields:
  ‘Quotetext’
  ‘QuoteBy’
  ‘QuoteUrl’
  
  I havent been able to get any output at all from this Matrix following the documentation and into following HTML structure:
  
  ```
  <blockquote>
      <p>Quotetext</p>
      <cite>QuoteBy</cite>
      <a href="QuoteUrl">QuoteUrl<a>
  </blockquote>
  
  ```
  
  Can anyone help me solve this issue?
  Thank you
  
  **Tags:** templating, matrix
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-04-26. Score: 2 | Accepted answer
  
  It might seem counter-intuitive in cases where you only have 1 *block type* (i.e. `quote`) and only a single block, but your Matrix field will always be an *array*, where the blocks (i.e. the "children" of the Matrix array) aren't directly accessible:
  
  ```
  entry.quotation
      - block1 (quote)
      ...
  
  ```
  
  Usually, you'll output your blocks by *looping* through the Matrix field, checking each block's type. I find that using a `{% switch %}` statement is often cleaner than an if/else:
  
  ```
  {% for block in entry.quotation %}
  
      {% switch block.type %}
  
           {% case 'quote' %}
           <blockquote>
               <p>{{ block.quoteText }}</p>
               <cite>{{ block.quoteBy }}</cite>
               <a href="{{ block.quoteUrl }}">QuoteUrl<a>
           </blockquote>
  
      {% endswitch %}
  
  {% endfor %}
  
  ```
  
  You can, however, opt to only output blocks of a certain type. This is done by "filtering" the Matrix field using the `type` method, and removes the need for the `switch` or if/else statement. This is convenient in cases where you know you'll only have 1 block type:
  
  ```
  {% for quote in entry.quotation.type( 'quote' ) %}
      <blockquote>
           <p>{{ quote.quoteText }}</p>
           <cite>{{ quote.quoteBy }}</cite>
           <a href="{{ quote.quoteUrl }}">QuoteUrl<a>
       </blockquote>
  {% endfor %}
  
  ```
  
  If you know there's only 1 block, you can even remove the loop entirely by explicitly targeting the `first` block for your filtered block type. The actual amount of code will be about the same as the above example, though:
  
  ```
  {% set quote = entry.quotation.type( 'quote' ).first %}
  {% if quote %}
      <blockquote>
          <p>{{ quote.quoteText }}</p>
          <cite>{{ quote.quoteBy }}</cite>
          <a href="{{ quote.quoteUrl }}">QuoteUrl<a>
      </blockquote>
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: I will use the {% switch %} technique in other areas of my build, thank you for that.Could you expand on your switch example and demo how to switch between text and image fields? (I have another area which has 2 Block Types: text, photo and within each is a field: text, photo. How I I have nested these is probably some of the reason I am having trouble.  
  > **username_1**: @username_0 No problem, happy to help out. If you create a new question for your other Matrix issue w/ the 2 block types, I'll be happy to take a look :)  
  > **username_0**: Thanks @mmikkel I have asked that question [link](http://craftcms.stackexchange.com/questions/9477/how-do-you-use-a-matrix-to-toggle-between-multiple-fields-from-multiple-blocks)  
  
  ---
  
  ### Answer by username_2 on 2015-04-26. Score: 1
  
  Since matrix blocks support more than one block you generally want to loop through the blocks, then grab the fields from each block (even if there is only one block defined).
  
  ```
  {% for block in entry.quotation %}
      {% if block.type == 'quote' %}
          <blockquote>
              <p>{{ block.quoteText }}</p>
              <cite>{{ block.quoteBy }}</cite>
              <a href="{{ block.quoteUrl }}">QuoteUrl<a>
          </blockquote>
      {% endif %}
  {% endfor %}
  
  ```
  
  Fyi... I'm using camel case in the example for all the field handles as it's the craft standard, but use whatever you use — just make sure it's actually the field 'handle' and not the field 'name'.
  
  
  ---
  
  