Skip to content

[5.x] resolve modifier #11890

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

Merged
merged 3 commits into from
Jul 7, 2025
Merged

Conversation

marcorieser
Copy link
Contributor

@marcorieser marcorieser commented Jun 22, 2025

I was missing the ability to get, for example, the first asset from an asset field ({{ asset_field | resolve(0) }}) or having a modifier to get a specific index from an array or a collection.

I was trying to extend the get modifier (#11889), but ran into some logical conflicts when providing a specific index for arrays. Therefore, I decided to build a simple new modifier. I was torn between resolve and retrieve.

So in short: The modifier resolves query builders and returns, if provided, the item for a specific index or just the whole array of data.

@daun
Copy link
Contributor

daun commented Jun 23, 2025

I've been using a custom resolve modifier for a while that did nothing but resolve query builder instances. Super useful! Could the key be optional? In that case { query | resolve } would only get the actual entries and return an array if the key is null.

@marcorieser
Copy link
Contributor Author

I've been using a custom resolve modifier for a while that did nothing but resolve query builder instances. Super useful! Could the key be optional? In that case { query | resolve } would only get the actual entries and return an array if the key is null.

Yeah, if you provide a key, the result is searched for that. If you dont provide a key, an array of all results is returned.

@daun
Copy link
Contributor

daun commented Jun 23, 2025

Oh, didn't know Arr::get($arr, null) worked like that! Nice!

@ryanmitchell
Copy link
Contributor

I wonder if the better thing to do might be to revert returning query builders at all, and always return resolved values. Then there could be a modifier to get the query builder for the (rare) times you really want that. It would simplify things greatly.

@marcorieser
Copy link
Contributor Author

Yeah, I agree. But the ability to grab an item by index from a collection or array and pass that into other modifiers would still be nice (and not possible until now?).

@edalzell
Copy link
Contributor

I wonder if the better thing to do might be to revert returning query builders at all, and always return resolved values. Then there could be a modifier to get the query builder for the (rare) times you really want that. It would simplify things greatly.

yaaaassss plz fren

@jasonvarga jasonvarga merged commit 8e8ee8d into statamic:5.x Jul 7, 2025
26 checks passed
@marcorieser marcorieser deleted the feat/resolve-modifier branch July 8, 2025 13:27
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

Successfully merging this pull request may close these issues.

5 participants