Sorting by Asset Name and Metadata values


(Nick Papadatos) #1

Matrix Version: 5.3

Hi Squiz folk

I have an asset Listing Page that I’m trying to do some sorting
example: sort each element by asset name (alphabetically and by metadata value start time)

A 9:30 am - 10:am
A 9:30 am - 10:am

B 10:00 am - 10:30 am
B 10:00 am - 10:30 am
etc

I can sort alphabetically using the keyword sort but how do I include the time (metadata) as well??

PS I got this to work using javascript but was a lot of mucking around, would be preferable to do it all within matrix - I’m still keen to hear from anyone who has had similar problems.

Cheers
Nick


Asset list - sorting grouped assets by date metadata
(Harinder Singh) #2

You can achieve this by having an another metadata text field and combine the values.

Use the following keywords(together) as default value of the text field

%asset_name%%metadata_field_XXXXXXX_start_time^date_format:hi%

Then, you can sort by this new metadata field. I have tested it at my end.

Note: don’t forget to disable the editing option for your content editors. Otherwise, anyone can modify it.


(Nick Papadatos) #3

Sounds like a plan and if I understand you correctly:

1: add another text field to the existing Schema (I called it custom_sort)
2: Add this to the default value
%asset_name%%metadata_field_XXXXXXX_start_time^date_format:hi%
I’m guessing XXXXXX is the field id of start_time
3: sorting on the asset listing sort by metadata and select the newly created metadata data field (custom_sort)

Now I must be doing something wrong because I see this value:

<meta name="custom_sort" content="Talking Global Studies with Culture and Heritage 
                       %metadata_field_1723808_start_date^date_format:hi%" />

Please note: start_date is a metadata date field not a text field.

Cheers
Nick


(Harinder Singh) #4

Use the name instead of ID


(Nick Papadatos) #5

Ok, got it - I’m still not 100% convinced that this works though unless I still don’t have the right settings:
From what I can gather the time format, say 1:00 pm = 0100 would sit higher than 9:00 am = 0900?

The sorting on the asset listing is: default sort-by option: metadata field, sort type: raw value, sort direction: descending.

But as you can see in the screen shot asset name - 0100 sits at the top. Have I missed something?


(Harinder Singh) #6

my bad. Use Capital H instead of small. It will convert it into 24 hour format.

%asset_name%%metadata_field_XXXXXXX_start_time^date_format:Hi%


(Nick Papadatos) #7

Thank you Harinder, worked on our test instance 5.5 but not on our prod instance 5.3.
I’ll keep this in my back pocket though for future reference.

Cheers
Nick


Sort By Time Metadata Value