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

Suggestion: hidden list field with current item index #172

Closed
josineto opened this issue Jun 25, 2024 · 5 comments
Closed

Suggestion: hidden list field with current item index #172

josineto opened this issue Jun 25, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@josineto
Copy link

The idea is: in a List widget with fields (e.g. not "simple string list"), one could add a hidden field that holds the index of the current item in that list, like:

list:
- fruit: apple
  index: 0 # <---
- fruit: banana
  index: 1 # <---

It could be a hidden widget with default: '{{index}}', or a compute widget with value: '{{index}}', or even something else...

@kyoshino
Copy link
Member

kyoshino commented Jun 25, 2024

I could add support for the index, but indexes can be easily retrieved in the framework, right? In Svelte, that’s the each block’s second callback argument, and in Hugo, range $index, $value := $slice

@josineto
Copy link
Author

josineto commented Jun 27, 2024

indexes can be easily retrieved in the framework

Not always: in Hugo, it's idiomatic to filter a collection right before looping into it (a range (where <collection> <filter> expression). In that case, the indexes are not relative to the original collection, but to the filtered one, so an index field would be useful.

@kyoshino
Copy link
Member

Okay, let’s see how the hidden index field would work.

@kyoshino kyoshino self-assigned this Jun 27, 2024
@kyoshino kyoshino added the enhancement New feature or request label Jun 27, 2024
@kyoshino
Copy link
Member

kyoshino commented Jul 3, 2024

The fix shipped with v0.35.0 🚢

You can now use widget: compute + value: '{{index}}'.

@josineto
Copy link
Author

josineto commented Jul 4, 2024

Thank you!

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

No branches or pull requests

2 participants