Skip to content

Sorting a complex array returns empty #13080

Description

@jarnalyrkar

Bug description

I saw this in the documentation:

Image

So I tried to make my own complex array and sort it, but it returns empty. I expected it to return a sorted array by the given value.

How to reproduce

I'm creating an array in antlers by getting specific fields from platforms, which is a field in the blueprint of taxonomy Countries:

{{ active_platforms = [] }}
{{ taxonomy:countries }}
{{ platforms }}
{{ if total_results > 0 and !(active_platforms|where("key", slug)) }}
{{ active_platforms += ["value" => title, "key" => slug] }}
{{ /if }}
{{ /platforms }}
{{ /taxonomy:countries }}
{{ active_platforms | sort="value" }}
{{ value }}
{{ /active_platforms }}

This is the dump of active_platforms:

array:3 [▼ // vendor/statamic/cms/src/Modifiers/CoreModifiers.php:622
0 => array:2 [▼
"value" => "Newgrounds"
"key" => "newgrounds"
]
1 => array:2 [▼
"value" => "Albinoblacksheep"
"key" => "albinoblacksheep"
]
2 => array:2 [▼
"value" => "Ebaumsworld"
"key" => "ebaumsworld"
]
]

Antlers Toolbox gives this error: Closing tags must match exactly when using shorthand modifiers in tag pairs. Adding the modifier to the ending tag makes the error go away, but looks weird and doesn't fix the problem.

As a way of sidestepping the issue; assigning the variable to a sorted version on the line just before the loop works:
{{ active_platforms = active_platforms | sort("value") }}

Logs

Environment

EnvironmentApplication Name: RedactedLaravel Version: 12.25.0PHP Version: 8.4.11Composer Version: 2.8.10Environment: localhostDebug Mode: ENABLEDURL: website.testMaintenance Mode: OFFTimezone: UTCLocale: enCacheConfig: NOT CACHEDEvents: NOT CACHEDRoutes: NOT CACHEDViews: CACHEDDriversBroadcasting: logCache: fileDatabase: mysqlLogs: stack / singleMail: smtpQueue: syncSession: fileStoragepublic/storage: NOT LINKEDStatamicAddons: 4Sites: 2 (English, Deutsch)Stache Watcher: EnabledStatic Caching: DisabledVersion: 5.63.0 PROStatamic Addonspecotamic/sitemap: 1.4.9rias/statamic-redirect: 3.12.0statamic/collaboration: 1.0.1transformstudios/review: 5.1.0

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions