twigcs
twigcs copied to clipboard
Variables set and used in loop should not be marked as unused
Steps required to reproduce the problem
{% set first = true %}
{% for part in content %}
{% if not first %}
<div style="page-break-after: always"></div>
{% else %}
{% set first = false %}
{% endif %}
{{ part|raw }}
{% endfor %}
Expected Result
- No warning
Actual Result
- l.6 c.9 : WARNING Unused variable "first".
Hi,
You need to use loop
instead https://twig.symfony.com/doc/2.x/tags/for.html
Like this :
{% for part in content %}
{% if not loop.first %}
<div style="page-break-after: always"></div>
{% endif %}
{{ part|raw }}
{% endfor %}
But i think it's a bug for the cs. Thanks to report !
Thank you, will use loop.first
instead!
Leaving this open as IMO this is still a valid twigcs issue ;)