Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables set and used in loop should not be marked as unused #257

Open
danog opened this issue Nov 15, 2022 · 2 comments
Open

Variables set and used in loop should not be marked as unused #257

danog opened this issue Nov 15, 2022 · 2 comments

Comments

@danog
Copy link

danog commented Nov 15, 2022

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".
@Ciloe
Copy link
Collaborator

Ciloe commented Nov 15, 2022

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 !

@danog
Copy link
Author

danog commented Nov 15, 2022

Thank you, will use loop.first instead!
Leaving this open as IMO this is still a valid twigcs issue ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants