Answers.Body: <p>Thought I would add this as an answer instead as it should solve your issue.</p>
  
  <p>I think the issue with writing it like <code>batch('{{ nr }}')</code> is that twig sees whatever is in <code>''</code> as a string, so is seeing <code>{{ nr }}</code> as it is.</p>
  
  <p>You also don't need to echo a variable as a function parameter i.e <code>batch({{ nr }})</code>, you just need to reference the variable itself.</p>
  
  <p>So by just writing</p>
  
  <pre><code>{% for batch in craft.entries.section('xy')|batch(nr) %}
   {{ batch.title }}
  {% endfor %
  </code></pre>
  
  <p>Twig will take the value for <code>nr</code> set above and use it as the parameter :)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-20T14:45:21.167Z
Answers.Text: Of course I didn't try the easiest possibility ;) thank you.
Answers.UserDisplayName: KSPR
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-20T13:47:11.653Z
Answers.LastActivityDate: 2015-05-20T13:47:11.653Z
Answers.UserDisplayName: Alec Ritson
Body: <p>I want to add a batch filter with a variable number depending on a conditional. Is this even possible this way:</p>
  
  <pre><code>{% if category.id == '647' %}
      {% set nr = '5' %}
  {% else %}
      {% set nr = '4' %}
  {% endif %}
  
  
  {% for batch in craft.entries.section('xy')|batch('{{ nr }}') %}
      {{ batch.title }}
  {% endfor %}
  </code></pre>
  
  <p>This doesn't work. How should I write <code>{{ nr }}</code> or is it impossible due to things like parse order?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-20T13:20:04.387Z
Comments.Text: Have you tried it as just `batch(nr)` ? without brackets and single quotes
Comments.UserDisplayName: Alec Ritson
Tags: <filter><batch>
Title: Add batch filter as variable
ThreadText: # Add batch filter as variable
  
  (Asked by: username_0 on 2015-05-20)
  
  I want to add a batch filter with a variable number depending on a conditional. Is this even possible this way:
  
  ```
  {% if category.id == '647' %}
      {% set nr = '5' %}
  {% else %}
      {% set nr = '4' %}
  {% endif %}
  
  {% for batch in craft.entries.section('xy')|batch('{{ nr }}') %}
      {{ batch.title }}
  {% endfor %}
  
  ```
  
  This doesn't work. How should I write `{{ nr }}` or is it impossible due to things like parse order?
  
  **Tags:** filter, batch
  
  > **Comments:**
  > **username_1**: Have you tried it as just `batch(nr)` ? without brackets and single quotes  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-05-20. Score: 6 | Accepted answer
  
  Thought I would add this as an answer instead as it should solve your issue.
  
  I think the issue with writing it like `batch('{{ nr }}')` is that twig sees whatever is in `''` as a string, so is seeing `{{ nr }}` as it is.
  
  You also don't need to echo a variable as a function parameter i.e `batch({{ nr }})`, you just need to reference the variable itself.
  
  So by just writing
  
  ```
  {% for batch in craft.entries.section('xy')|batch(nr) %}
   {{ batch.title }}
  {% endfor %
  
  ```
  
  Twig will take the value for `nr` set above and use it as the parameter :)
  
  > **Comments:**
  > **username_0**: Of course I didn't try the easiest possibility ;) thank you.  
  
  ---
  
  