Answers.Body: <p>Without understanding your use case or having the context of your full template and/or Matrix loop, it's very difficult to provide a good answer.</p>
  
  <p>If you only want to "wrap all outputted blocks" in a container, it's as easy as putting the Matrix loop in a container, e.g.:</p>
  
  <pre><code>&lt;div class="wrapper"&gt;
      {% for block in entry.myMatrixFieldHandle %}
          {% switch block.type %}
              {% case 'artworkText' %}
                  ...
              {% case 'artworkImageSingle' %}
                  ...
              {% case 'artworkImageDouble' %}
                  ...
              {% case 'artworkFile' %}
              {% for asset in block.downloadUrl %}
                  &lt;a href="{{ asset.getUrl() }}" target="_blank"&gt;
                      &lt;div class="file {{ block.platform }} gutter-bottom--half"&gt;&lt;/div&gt;
                  &lt;/a&gt;
              {% endfor %}
          {% endswitch %}
      {% endfor %}
  &lt;/div&gt;
  </code></pre>
  
  <p>Based on your comments, however, I suspect that what you really want is to only wrap the markup for all your <code>artworkFile</code> blocks.</p>
  
  <p>If that is the case, you have to consider the fact that if you want to wrap all of the <code>artworkFile</code> blocks in a single container and not the other block types, then these <code>artworkFile</code> blocks will necessarily be removed from the general flow/chronology of your overall Matrix field. This may be exactly what you want, or a side effect you haven't considered - just wanted to mention it. (It also means that you could actually just move the <code>artworkFile</code> blocks to a separate Matrix field altogether, if that'd make any of this easier).</p>
  
  <p>Anyway, there's at least a couple of ways to achieve the above with your current setup. </p>
  
  <p>First, you can opt to remove the <code>artworkFile</code> switch case from your current Matrix loop, and create a secondary loop which only loops on <code>artworkFile</code> blocks somewhere else in your template. This secondary loop is then wrapped in a <code>&lt;div class="wrapper"&gt;</code> container, e.g.:</p>
  
  <pre><code>&lt;div class="wrapper"&gt;
      {% for block in entry.myMatrixFieldHandle.type('artworkFile') %}
          {% for asset in block.downloadUrl %}
          &lt;a href="{{ asset.getUrl() }}" target="_blank"&gt;
              &lt;div class="file {{ block.platform }} gutter-bottom--half"&gt;&lt;/div&gt;
          &lt;/a&gt;
          {% endfor %}
      {% endfor %}
  &lt;/div&gt;
  </code></pre>
  
  <p>Another option is to leave the <code>artworkFile</code> switch in your current Matrix loop, but instead of outputting the markup directly, you can cache it in an array – this is done by first putting the markup in a variable by wrapping the block markup in a <code>{% set %}</code> tag pair, adding that variable to an array declared outside the loop, and finally print the collected markup by joining the contents of that array inside a container, e.g.:</p>
  
  <pre><code>{# Create an empty array outside the loop #}
  {% set artworkFileBlocks = [] %}
  {% for block in entry.myMatrixFieldHandle %}
      {% switch block.type %}
          {% case 'artworkText' %}
              ...
          {% case 'artworkImageSingle' %}
              ...
          {% case 'artworkImageDouble' %}
              ...
          {% case 'artworkFile' %}
          {# Cache the markup for the artworkFile block to a variable #}
          {% set artworkFileBlock %}
              {% for asset in block.downloadUrl %}
                  &lt;a href="{{ asset.getUrl() }}" target="_blank"&gt;
                      &lt;div class="file {{ block.platform }} gutter-bottom--half"&gt;&lt;/div&gt;
                  &lt;/a&gt;
              {% endfor %}
          {% endset %}
          {# Add the single artworkFile block markup to the array #}
          {% set artworkFileBlocks = artworkFileBlocks|merge([artworkFileBlock]) %}
      {% endswitch %}
  {% endfor %}
  
  {# Echo all artworkFile markup in a common container, whereever you need it #}
  &lt;div class="wrapper"&gt;
      {{ artworkFileBlocks|join('')|raw }}
  &lt;/div&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-22T10:30:37.603Z
Answers.Text: Thanks for such a detailed answer. I wanted to keep the artworkFile block within the Matrix so it can be moved around within the rest of the content.
Answers.UserDisplayName: sarah3585
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-22T12:07:49.983Z
Answers.Text: Right, that's a valid reason to keep all the block types in a single Matrix field, even if the `artworkFile` blocks aren't output with the other block types.
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-21T19:20:08.783Z
Answers.LastActivityDate: 2015-11-21T19:20:08.783Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.Body: <p>If you just want to affect the <code>artworkFile</code> blocks, you could do this:</p>
  
  <pre><code>{% case "artworkFile" %}
  {% for asset in block.downloadUrl %}
      {% if loop.first %}&lt;div class="wrapper"&gt;{% endif %}
      &lt;a href="{{ asset.getUrl() }}" target="_blank"&gt;
      &lt;div class="file {{ block.platform }} gutter-bottom--half"&gt;&lt;/div&gt;&lt;/a&gt;
      {% if loop.last %}&lt;/div&gt;{% endif %}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-20T16:28:06.937Z
Answers.Text: Thanks. This seems to wrap all individual fields rather than all. I've updated my questions with more information.
Answers.UserDisplayName: sarah3585
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-17T14:39:28.927Z
Answers.LastActivityDate: 2015-11-17T14:39:28.927Z
Answers.UserDisplayName: Steve Rowling
Body: <p>I'm outputting fields from a Matrix block, how do I then wrap all outputted fields from 'artworkFile' that are available with some HTML. Not individually wrapped, but all outputted fields.</p>
  
  <p>Current Code:</p>
  
  <pre><code>{% case "artworkFile" %}
  {% for asset in block.downloadUrl %}
   &lt;a href="{{ asset.getUrl() }}" target="_blank"&gt;
   &lt;div class="file {{ block.platform }} gutter-bottom--half"&gt;&lt;/div&gt;&lt;/a&gt;
  {% endfor %}
  </code></pre>
  
  <p>Desired Output</p>
  
  <pre><code>&lt;div class="wrapper"&gt;
    &lt;a href="asseturl1.png&gt;
     &lt;div class="file exampleplatform1 gutter-bottom--half"&gt;&lt;/div&gt;
    &lt;/a&gt;
    &lt;a href="asseturl2.png&gt;
     &lt;div class="file exampleplatform2 gutter-bottom--half"&gt;&lt;/div&gt;
    &lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Matrix Setup
  <a href="https://i.sstatic.net/jAPs1.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jAPs1.png" alt="enter image description here"></a></p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-16T11:56:26.923Z
Comments.Text: The use case is missing here, which makes your question hard to answer – you might want to include more of your current template code. Is there are reason why you can't just wrap the Matrix loop in a container, i.e. `<div class="wrapper">{% for block in myMatrixField %}...{% endfor %}</div>`?
Comments.UserDisplayName: Mats Mikkel Rummelhoff
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-20T16:23:34.607Z
Comments.Text: That seems to wrap each block in a 'wrapper' I want it to wrap all outputted blocks. I will update my question for more information.
Comments.UserDisplayName: sarah3585
Tags: <matrix><loop><batch>
Title: Wrapping a matrix block
ThreadText: # Wrapping a matrix block
  
  (Asked by: username_0 on 2015-11-16)
  
  I'm outputting fields from a Matrix block, how do I then wrap all outputted fields from 'artworkFile' that are available with some HTML. Not individually wrapped, but all outputted fields.
  
  Current Code:
  
  ```
  {% case "artworkFile" %}
  {% for asset in block.downloadUrl %}
   <a href="{{ asset.getUrl() }}" target="_blank">
   <div class="file {{ block.platform }} gutter-bottom--half"></div></a>
  {% endfor %}
  
  ```
  
  Desired Output
  
  ```
  <div class="wrapper">
    <a href="asseturl1.png>
     <div class="file exampleplatform1 gutter-bottom--half"></div>
    </a>
    <a href="asseturl2.png>
     <div class="file exampleplatform2 gutter-bottom--half"></div>
    </a>
  </div>
  
  ```
  
  Matrix Setup
  [![enter image description here](https://i.sstatic.net/jAPs1.png)](https://i.sstatic.net/jAPs1.png)
  
  **Tags:** matrix, loop, batch
  
  > **Comments:**
  > **username_1**: The use case is missing here, which makes your question hard to answer – you might want to include more of your current template code. Is there are reason why you can't just wrap the Matrix loop in a container, i.e. `<div class="wrapper">{% for block in myMatrixField %}...{% endfor %}</div>`?  
  > **username_0**: That seems to wrap each block in a 'wrapper' I want it to wrap all outputted blocks. I will update my question for more information.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-11-21. Score: 3
  
  Without understanding your use case or having the context of your full template and/or Matrix loop, it's very difficult to provide a good answer.
  
  If you only want to "wrap all outputted blocks" in a container, it's as easy as putting the Matrix loop in a container, e.g.:
  
  ```
  <div class="wrapper">
      {% for block in entry.myMatrixFieldHandle %}
          {% switch block.type %}
              {% case 'artworkText' %}
                  ...
              {% case 'artworkImageSingle' %}
                  ...
              {% case 'artworkImageDouble' %}
                  ...
              {% case 'artworkFile' %}
              {% for asset in block.downloadUrl %}
                  <a href="{{ asset.getUrl() }}" target="_blank">
                      <div class="file {{ block.platform }} gutter-bottom--half"></div>
                  </a>
              {% endfor %}
          {% endswitch %}
      {% endfor %}
  </div>
  
  ```
  
  Based on your comments, however, I suspect that what you really want is to only wrap the markup for all your `artworkFile` blocks.
  
  If that is the case, you have to consider the fact that if you want to wrap all of the `artworkFile` blocks in a single container and not the other block types, then these `artworkFile` blocks will necessarily be removed from the general flow/chronology of your overall Matrix field. This may be exactly what you want, or a side effect you haven't considered - just wanted to mention it. (It also means that you could actually just move the `artworkFile` blocks to a separate Matrix field altogether, if that'd make any of this easier).
  
  Anyway, there's at least a couple of ways to achieve the above with your current setup.
  
  First, you can opt to remove the `artworkFile` switch case from your current Matrix loop, and create a secondary loop which only loops on `artworkFile` blocks somewhere else in your template. This secondary loop is then wrapped in a `<div class="wrapper">` container, e.g.:
  
  ```
  <div class="wrapper">
      {% for block in entry.myMatrixFieldHandle.type('artworkFile') %}
          {% for asset in block.downloadUrl %}
          <a href="{{ asset.getUrl() }}" target="_blank">
              <div class="file {{ block.platform }} gutter-bottom--half"></div>
          </a>
          {% endfor %}
      {% endfor %}
  </div>
  
  ```
  
  Another option is to leave the `artworkFile` switch in your current Matrix loop, but instead of outputting the markup directly, you can cache it in an array – this is done by first putting the markup in a variable by wrapping the block markup in a `{% set %}` tag pair, adding that variable to an array declared outside the loop, and finally print the collected markup by joining the contents of that array inside a container, e.g.:
  
  ```
  {# Create an empty array outside the loop #}
  {% set artworkFileBlocks = [] %}
  {% for block in entry.myMatrixFieldHandle %}
      {% switch block.type %}
          {% case 'artworkText' %}
              ...
          {% case 'artworkImageSingle' %}
              ...
          {% case 'artworkImageDouble' %}
              ...
          {% case 'artworkFile' %}
          {# Cache the markup for the artworkFile block to a variable #}
          {% set artworkFileBlock %}
              {% for asset in block.downloadUrl %}
                  <a href="{{ asset.getUrl() }}" target="_blank">
                      <div class="file {{ block.platform }} gutter-bottom--half"></div>
                  </a>
              {% endfor %}
          {% endset %}
          {# Add the single artworkFile block markup to the array #}
          {% set artworkFileBlocks = artworkFileBlocks|merge([artworkFileBlock]) %}
      {% endswitch %}
  {% endfor %}
  
  {# Echo all artworkFile markup in a common container, whereever you need it #}
  <div class="wrapper">
      {{ artworkFileBlocks|join('')|raw }}
  </div>
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks for such a detailed answer. I wanted to keep the artworkFile block within the Matrix so it can be moved around within the rest of the content.  
  > **username_1**: Right, that's a valid reason to keep all the block types in a single Matrix field, even if the `artworkFile` blocks aren't output with the other block types.  
  
  ---
  
  ### Answer by username_2 on 2015-11-17. Score: 1
  
  If you just want to affect the `artworkFile` blocks, you could do this:
  
  ```
  {% case "artworkFile" %}
  {% for asset in block.downloadUrl %}
      {% if loop.first %}<div class="wrapper">{% endif %}
      <a href="{{ asset.getUrl() }}" target="_blank">
      <div class="file {{ block.platform }} gutter-bottom--half"></div></a>
      {% if loop.last %}</div>{% endif %}
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks. This seems to wrap all individual fields rather than all. I've updated my questions with more information.  
  
  ---
  
  