Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

UniqueHope's avatar

Alpine, how to dynamically show items based on multiple values?

In a list of items(components) the items can be active or not. And as a default I'm showing 4 items, only the 'active' ones.

There are also 2 buttons, one will show the full list, not just the first 4. And the other shows non-active items as well.

The difficulty I'm getting is then lets say you click the show non-active items, how to set it up so the 4 items now shift to work properly if there happens to be an item that isn't active somewhere there. Basically in a set of (active, active, not, active, active) at the start it shows all but the 3rd one, but after clicking that button the 5th one isn't there and the 3rd one shows instead.

Currently trying out a nested setup where the values for show all and show actives are on the container and the individual item active states are on the items.

0 likes
2 replies
Snapey's avatar

each individual item needs to check if the current state (active or inactive) matches to its own state, and perform this check within x-show

UniqueHope's avatar

That much is currently working, but how to tell what the first 4 shown items are, depending on if I'm trying to show inactive items or not?

Please or to participate in this conversation.