Add batch filter as variable 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?
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 :)