Answers.Body: <p>Great question! While seemingly tricky, the solution to this should be relatively simple...</p>
  <p>Per the <a href="https://plugins.doublesecretagency.com/smart-map/render-a-map-in-twig/" rel="nofollow noreferrer">documentation</a>, the <code>locations</code> parameter can come in a variety of different forms. But the one we're looking for here is this one...</p>
  <blockquote>
  <p><strong>As an array of elements</strong></p>
  </blockquote>
  <p>Collecting Matrix blocks from across different entries can be complicated, but I think you have (fortunately) described a fairly straightforward use-case. We'll need to do the following:</p>
  <ol>
  <li>Loop through relevant entries.</li>
  <li>Build <em>an array of Matrix blocks</em>.</li>
  <li>Use that array to render a map.</li>
  </ol>
  <hr />
  <pre><code>{# Initialize locations array #}
  {% set locationsArray = [] %}
  
  {# Loop through all relevant entries #}
  {% for entry in craft.entries.section('buildings').find() %}
  
      {# Get all relevant Matrix blocks #}
      {% set matrixBlocks = entry.buildingContent.type('howToGetThere').find() %}
  
      {# Append blocks to locations array #}
      {% set locationsArray = locationsArray|merge(matrixBlocks) %}
  
  {% endfor %}
  
  {# Render map #}
  {{ craft.smartMap.map(locationsArray, options) }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-25T16:05:37.007Z
Answers.Text: Thanks so much Lindsey, this has worked a treat and all the locations are now showing on the single map!
Answers.UserDisplayName: H. Ng
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2017-06-25T15:27:39.683Z
Answers.LastActivityDate: 2021-01-01T06:52:31.433Z
Answers.LastEditDate: 2021-01-01T06:52:31.433Z
Answers.UserDisplayName: Lindsey D
Body: <p>I'm using the Smart Map plugin, and I can't seem to figure out how to output all the locations of my entries from a single section onto one single map.</p>
  <p>I think the issue I'm having is trying to get the information out from a Matrix block within each entry or knowing where to start!</p>
  <p>The section is 'buildings' which contains all the building entries. For each entry, there is a matrix block called 'buildingContent' which has 5 matrix blocks, and the one I want to pull information from is 'howToGetThere' (last block out of the matrix array). In this block, I have a field 'smartMap' which contains the location of the building.</p>
  <p>How would I extract the location from the 'smartMap' field for all my entries and output them onto one single map?</p>
  <p>I know the code below outputs the location of one entry (St Bartholomew The Great), but thought it might be useful to include what I've tried so far. I adapted it from the <a href="https://plugins.doublesecretagency.com/smart-map/how-to-use-with-a-matrix-field/" rel="nofollow noreferrer">documentation</a>:</p>
  <pre><code>{% set entry = craft.entries.slug('st-bartholomew-the-great').first %}
  
  {% set locations = entry.buildingContent %}
  
  {% set options = {
       height: 600,
       zoom: 13,
       draggable: true,
       markerInfo: '_includes/mapInfoBubble',
       markerOptions: {
          icon: 'images/map-marker2.svg',
       }
   } %}
  
  {{ craft.smartMap.map(locations[4], options) }}
  </code></pre>
  <p>Any help much appreciated, thanks!</p>
  
Tags: <matrix><plugin-smartmap><output>
Title: Smart Map - Outputting locations from a Matrix field for all entries within a single section
ThreadText: # Smart Map - Outputting locations from a Matrix field for all entries within a single section
  
  (Asked by: username_0 on 2017-06-25)
  
  I'm using the Smart Map plugin, and I can't seem to figure out how to output all the locations of my entries from a single section onto one single map.
  
  I think the issue I'm having is trying to get the information out from a Matrix block within each entry or knowing where to start!
  
  The section is 'buildings' which contains all the building entries. For each entry, there is a matrix block called 'buildingContent' which has 5 matrix blocks, and the one I want to pull information from is 'howToGetThere' (last block out of the matrix array). In this block, I have a field 'smartMap' which contains the location of the building.
  
  How would I extract the location from the 'smartMap' field for all my entries and output them onto one single map?
  
  I know the code below outputs the location of one entry (St Bartholomew The Great), but thought it might be useful to include what I've tried so far. I adapted it from the [documentation](https://plugins.doublesecretagency.com/smart-map/how-to-use-with-a-matrix-field/):
  
  ```
  {% set entry = craft.entries.slug('st-bartholomew-the-great').first %}
  
  {% set locations = entry.buildingContent %}
  
  {% set options = {
       height: 600,
       zoom: 13,
       draggable: true,
       markerInfo: '_includes/mapInfoBubble',
       markerOptions: {
          icon: 'images/map-marker2.svg',
       }
   } %}
  
  {{ craft.smartMap.map(locations[4], options) }}
  
  ```
  
  Any help much appreciated, thanks!
  
  **Tags:** matrix, plugin-smartmap, output
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-06-25. Score: 2 | Accepted answer
  
  Great question! While seemingly tricky, the solution to this should be relatively simple...
  
  Per the [documentation](https://plugins.doublesecretagency.com/smart-map/render-a-map-in-twig/), the `locations` parameter can come in a variety of different forms. But the one we're looking for here is this one...
  
  > **As an array of elements**
  
  Collecting Matrix blocks from across different entries can be complicated, but I think you have (fortunately) described a fairly straightforward use-case. We'll need to do the following:
  
  1. Loop through relevant entries.
  2. Build *an array of Matrix blocks*.
  3. Use that array to render a map.
  
  ---
  
  ```
  {# Initialize locations array #}
  {% set locationsArray = [] %}
  
  {# Loop through all relevant entries #}
  {% for entry in craft.entries.section('buildings').find() %}
  
      {# Get all relevant Matrix blocks #}
      {% set matrixBlocks = entry.buildingContent.type('howToGetThere').find() %}
  
      {# Append blocks to locations array #}
      {% set locationsArray = locationsArray|merge(matrixBlocks) %}
  
  {% endfor %}
  
  {# Render map #}
  {{ craft.smartMap.map(locationsArray, options) }}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks so much username_1, this has worked a treat and all the locations are now showing on the single map!  
  
  ---
  
  