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

{skipIf} does not avoid printing last {sep} #263

Open
JanTvrdik opened this issue Mar 16, 2021 · 2 comments
Open

{skipIf} does not avoid printing last {sep} #263

JanTvrdik opened this issue Mar 16, 2021 · 2 comments

Comments

@JanTvrdik
Copy link
Contributor

Version: 2.10.3

Steps To Reproduce

{foreach [1, 2, 3] as $item}
    {skipIf $item === 3}
    {$item}{sep}, {/sep}
{/foreach}

https://fiddle.nette.org/latte/#14e8be81e2

Expected Behavior

The last comma should not be printed.

@dg
Copy link
Member

dg commented Mar 16, 2021

How could this be solved?

@JanTvrdik
Copy link
Contributor Author

JanTvrdik commented Mar 17, 2021

I don't know. The only thing I can think of is to compile the {skipIf} to sth like $iterator->setFilter(fn($it) => $it === 3)), so the iterator itself is aware of the filter in order to properly evaluate isLast().

But that will of course work only in very limited set of scenarios, i.e. skipIf must be top-level and the expression may depend only on entry key/value. So it would probably need a custom syntax to make it actually work well, i.e. sth like

{foreach [1, 2, 3] as $item where $item === 3}
    {$item}{sep}, {/sep}
{/foreach}

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