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

Is there a way to get index in for loop? #148

Closed
mikesmobile opened this issue Sep 4, 2020 · 6 comments
Closed

Is there a way to get index in for loop? #148

mikesmobile opened this issue Sep 4, 2020 · 6 comments
Labels

Comments

@mikesmobile
Copy link

Hello love your pluggin,

I have {FOR issue IN $component.issues} and would love to also be able to use the index in this. have tried

{FOR issue, index IN $component.issues}
and
{FOR (issue, index) IN $component.issues} {var count=1}

Any help would be much appreciated. basically looking to add page break only at the end of this for loop.

@mathe42
Copy link
Contributor

mathe42 commented Sep 4, 2020

You can use

+++EXEC
let i = 0;
+++

+++FOR issue IN $component.issues+++
  // normal Word
 
  +++=i+++
 
  +++EXEC i=i+1 +++
+++END FOR $component+++

as a workaround

@mikesmobile
Copy link
Author

mikesmobile commented Sep 4, 2020 via email

@mathe42
Copy link
Contributor

mathe42 commented Sep 4, 2020

Thanks :D

@jjhbw jjhbw added the question label Sep 5, 2020
@jjhbw
Copy link
Collaborator

jjhbw commented Sep 10, 2020

Thanks @mathe42 for your idea!

At the moment the approach mentioned by @mathe42 is best. I will log this as a potential feature for later, but ATM I'm reluctant to implement it because it requires really deep changes.

@davidjb
Copy link
Contributor

davidjb commented Aug 16, 2023

Just a heads up that $idx was actually available all along within loops (see #65 and formalised and documented in #323.) but it does only refer to the inner-most index so it's not exactly the same thing when it comes to having arbitrary indicies in nested loops.

As for the conditional page break use case though just having the inner-most index is probably sufficient; I solved this like so #283 (comment).

@jjhbw
Copy link
Collaborator

jjhbw commented Aug 16, 2023

Thanks for taking the time to answer these older issues @davidjb , really appreciated.

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

No branches or pull requests

3 participants