cms icon indicating copy to clipboard operation
cms copied to clipboard

Sorting a complex array returns empty

Open jarnalyrkar opened this issue 2 months ago • 0 comments

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

Environment
Application Name: Redacted
Laravel Version: 12.25.0
PHP Version: 8.4.11
Composer Version: 2.8.10
Environment: localhost
Debug Mode: ENABLED
URL: website.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Storage
public/storage: NOT LINKED

Statamic
Addons: 4
Sites: 2 (English, Deutsch)
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.63.0 PRO

Statamic Addons
pecotamic/sitemap: 1.4.9
rias/statamic-redirect: 3.12.0
statamic/collaboration: 1.0.1
transformstudios/review: 5.1.0

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

jarnalyrkar avatar Nov 18 '25 07:11 jarnalyrkar