Answers.Body: <p>You don't want braces within braces.</p>
  
  <p>You want something like this instead:</p>
  
  <pre><code>{% set index = craft.entries.section(sectionName ~ 'Index').first %}
  </code></pre>
  
  <p>Same needs changing in the for loop.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-06T21:15:49.577Z
Answers.Text: Gah! Of course! Thank you. And for the heads up on the ~
Answers.UserDisplayName: Matt Ellis
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-06T17:31:04.533Z
Answers.LastActivityDate: 2016-01-06T17:31:04.533Z
Answers.UserDisplayName: Jamie Pittock
Body: <p>I'm trying to use a macro to output a list of entries (and the title of a section), this is my code:</p>
  
  <pre><code>{% macro sections(sectionName)%}
  
      {% set index = craft.entries.section('{{ sectionName }}Index').first %}
      &lt;h3&gt;{{ index.getLink() }}&lt;/h3&gt;
  
      {% for entry in craft.entries.section('{{ sectionName }}').order('title') %}
  
          {{ loop.first ? '&lt;ul&gt;'}}
              &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt; {{ sectionName }}&lt;/li&gt;
          {{ loop.last ? '&lt;/ul&gt;'}}
  
      {% endfor %}
  {% endmacro %}
  
  {{ _self.sections('about') }}
  {{ _self.sections('information') }}
  {{ _self.sections('galleries') }}
  </code></pre>
  
  <p>But this displays ALL entries. However, if I hardcode the section names (for each loop) it works, though not DRY.</p>
  
  <p>This is my first attempt at using a macro, seemed like a good place to use one?</p>
  
Tags: <entries><sections><macro>
Title: Using a macro for entries loop
ThreadText: # Using a macro for entries loop
  
  (Asked by: username_0 on 2016-01-06)
  
  I'm trying to use a macro to output a list of entries (and the title of a section), this is my code:
  
  ```
  {% macro sections(sectionName)%}
  
      {% set index = craft.entries.section('{{ sectionName }}Index').first %}
      <h3>{{ index.getLink() }}</h3>
  
      {% for entry in craft.entries.section('{{ sectionName }}').order('title') %}
  
          {{ loop.first ? '<ul>'}}
              <li><a href="{{ entry.url }}">{{ entry.title }}</a> {{ sectionName }}</li>
          {{ loop.last ? '</ul>'}}
  
      {% endfor %}
  {% endmacro %}
  
  {{ _self.sections('about') }}
  {{ _self.sections('information') }}
  {{ _self.sections('galleries') }}
  
  ```
  
  But this displays ALL entries. However, if I hardcode the section names (for each loop) it works, though not DRY.
  
  This is my first attempt at using a macro, seemed like a good place to use one?
  
  **Tags:** entries, sections, macro
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-01-06. Score: 3 | Accepted answer
  
  You don't want braces within braces.
  
  You want something like this instead:
  
  ```
  {% set index = craft.entries.section(sectionName ~ 'Index').first %}
  
  ```
  
  Same needs changing in the for loop.
  
  > **Comments:**
  > **username_0**: Gah! Of course! Thank you. And for the heads up on the ~  
  
  ---
  
  