Answers.Body: <p>The <a href="http://twig.sensiolabs.org/doc/functions/attribute.html" rel="nofollow">Twig attribute function</a> solved this for me. Thanks to @tom-bauer</p>
  
  <p>Revised Template Code:</p>
  
  <pre><code>{% set newsSectionIds = craft.entries.section('news').ids() %}
  {% set pressSectionIds = craft.entries.section('press').ids() %}
  {% set entryIds = newsSectionIds|merge(pressSectionIds) %}
  {% set entries = craft.entries.id(entryIds) %}
  
  {% for entry in entries %}
  
      {% set sectionMatrix = attribute(entry, "entryMatrix"~entry.section) %}
  
      {% for block in sectionMatrix %}
  
          {# my matrix code #}
  
      {% endfor %}
  
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-24T14:44:53.950Z
Answers.Text: You can also use the subscript syntax: `entry["entryMatrix"~entry.section]`.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-24T15:37:41.513Z
Answers.Text: Thank you. This works perfectly, and is slightly shorter too.
Answers.UserDisplayName: Andrew F
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-24T14:02:49.703Z
Answers.LastActivityDate: 2016-02-24T14:02:49.703Z
Answers.UserDisplayName: Andrew F
Body: <p>I'm trying to merge a field name prefix with entry.section to make a dynamic field handle. I'm guessing I'm setting the sectionMatrix variable incorrectly, causing the code to fail without error. Any tips would be greatly appreciated.</p>
  
  <p>Channels:</p>
  
  <ul>
  <li>News</li>
  <li>Press</li>
  </ul>
  
  <p>Each channel has is own matrix field, with different blocks:</p>
  
  <ul>
  <li>entryMatrixNews</li>
  <li>entryMatrixPress</li>
  </ul>
  
  <p>Template Code:</p>
  
  <pre><code>{% set newsSectionIds = craft.entries.section('news').ids() %}
  {% set pressSectionIds = craft.entries.section('press').ids() %}
  {% set entryIds = newsSectionIds|merge(pressSectionIds) %}
  {% set entries = craft.entries.id(entryIds) %}
  
  {% for entry in entries %}
     {% set sectionMatrix = 'entry.entryMatrix' ~ entry.section %}
     {# sectionMatrix then equals either entry.entryMatrixNews or entry.entryMatrixPress #}
  
     {% for block in sectionMatrix %}
        {# my matrix code #}
     {% endfor %}
  
  {% endfor %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-23T18:01:27.903Z
Comments.Text: Take a look on these two Answers: - http://craftcms.stackexchange.com/questions/12627/parse-a-string-dynamic-in-twig - http://craftcms.stackexchange.com/questions/13336/variable-variables-in-twig
Comments.UserDisplayName: Tom Bauer
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-02-24T13:51:54.860Z
Comments.Text: Thanks Tom! The **attribute() twig function** example suggested by @taylor worked perfectly.
Comments.UserDisplayName: Andrew F
Tags: <matrix><fieldtypes>
Title: Is it possible to merge entry parameters to create a dynamic field handle?
ThreadText: # Is it possible to merge entry parameters to create a dynamic field handle?
  
  (Asked by: username_0 on 2016-02-23)
  
  I'm trying to merge a field name prefix with entry.section to make a dynamic field handle. I'm guessing I'm setting the sectionMatrix variable incorrectly, causing the code to fail without error. Any tips would be greatly appreciated.
  
  Channels:
  
  * News
  * Press
  
  Each channel has is own matrix field, with different blocks:
  
  * entryMatrixNews
  * entryMatrixPress
  
  Template Code:
  
  ```
  {% set newsSectionIds = craft.entries.section('news').ids() %}
  {% set pressSectionIds = craft.entries.section('press').ids() %}
  {% set entryIds = newsSectionIds|merge(pressSectionIds) %}
  {% set entries = craft.entries.id(entryIds) %}
  
  {% for entry in entries %}
     {% set sectionMatrix = 'entry.entryMatrix' ~ entry.section %}
     {# sectionMatrix then equals either entry.entryMatrixNews or entry.entryMatrixPress #}
  
     {% for block in sectionMatrix %}
        {# my matrix code #}
     {% endfor %}
  
  {% endfor %}
  
  ```
  
  **Tags:** matrix, fieldtypes
  
  > **Comments:**
  > **username_1**: Take a look on these two Answers: - http://craftcms.stackexchange.com/questions/12627/parse-a-string-dynamic-in-twig - http://craftcms.stackexchange.com/questions/13336/variable-variables-in-twig  
  > **username_0**: Thanks Tom! The **attribute() twig function** example suggested by @taylor worked perfectly.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-02-24. Score: 2
  
  The [Twig attribute function](http://twig.sensiolabs.org/doc/functions/attribute.html) solved this for me. Thanks to @username_1
  
  Revised Template Code:
  
  ```
  {% set newsSectionIds = craft.entries.section('news').ids() %}
  {% set pressSectionIds = craft.entries.section('press').ids() %}
  {% set entryIds = newsSectionIds|merge(pressSectionIds) %}
  {% set entries = craft.entries.id(entryIds) %}
  
  {% for entry in entries %}
  
      {% set sectionMatrix = attribute(entry, "entryMatrix"~entry.section) %}
  
      {% for block in sectionMatrix %}
  
          {# my matrix code #}
  
      {% endfor %}
  
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_2**: You can also use the subscript syntax: `entry["entryMatrix"~entry.section]`.  
  > **username_0**: Thank you. This works perfectly, and is slightly shorter too.  
  
  ---
  
  