Pass sorting value to asset list nested in a component


(Margaret Chatwin) #1

We’ve set up a ‘tiles’ component that allows a user to select a root node and those pages then display as tiles. They have a number of other options, such as whether to display thumbnails and descriptions etc. I’ve even been able to add the option to limit the list to a specified number. I’d also like to provide the option to choose how the tiles are sorted.

For the limit, the user enters a number into the provided text field. In the component’s paint layout, where the asset list is nested, it has the additional get parameter of tiles.limit - %globals_asset_metadata_tiles.limit% and then in the asset list it has %nested_get_tiles.limit^empty:100% in the assets per page field.

Now, I realise that asset sorting doesn’t have a field in which you can enter a keyword like the assets per page field, but is there a way to pass in the appropriate query string as below (where xxxxxx is the asset ID of the asset listing, and the final number would change depending on what sort you wanted)?

?page_asset_listing_xxxxxx_sort_by=0

I did have a play around with it and couldn’t get it to work, but I don’t know if that’s because it’s just not possible, or because I was putting variables in the wrong places.

Thanks!


(Kieran) #2

Hi Margaret,
I havent got anything set up to test this, but “sort_by” would usually be put on the listing bodycopy to show a dropdown of options of which to sort by.
You could try using this, showing the options, selecting one and then hitting submit, and seeing if it adds a “sort_by” or similar to the URL, and follow that.

If you were able to pass the variable via URL, you’d be separating variables with “&”, so if you were on the right track above, you’d use something more like: ?page_asset_listing_xxxxxx & sort_by=0


(Iain Simmons) #3

Hi @margaret.chatwin,

Yes, you can use query parameters to change the sorting, but they need to first be configured on the Asset Sorting screen, and then you’d need to get the query parameter, which is generally easier by adding it to the page contents of the listing:

Example of Setting Up and Showing the Sorting List

The keyword to show the sort by selector is %sort_by%, and you would also need a %submit_button% in the page contents, before or after the %asset_listing%.

Add that to the page contents, then preview the asset listing and change the sorting and submit to see the query parameter being used.

Note that the number used as the value maps to the list of options configured on the Asset Sorting screen, so you’ll need to add, remove or change the order of those options and get the number matching from your component’s metadata/paint layout.

Cheers,
iain


(Margaret Chatwin) #4

Thanks both of you for your tips. Due to other commitments at work and then some leave, I’ve only just had a chance to have a proper look. However what you suggested was pretty much what I had already tried previously.

It turned out the problem was what I was putting in the Additional GET Parameters section of the nested content - a slight misunderstanding on my part of how the variable names work. However, I’ve now figured it out.

As you can see from the screenshot (at least partially), I have page_asset_listing_328901_sort_by as the variable name and %globals_asset_metadata_listing.sort_key% as the variable value.

This works (hooray!), but if possible I’d prefer to use a keyword for the asset listing’s ID, to make this easier to copy across to different components. I have tried, but then it stops working.

It does not like the variable name to be page_asset_listing_%nested_asset_assetid%_sort_by. Any ideas?

We’re on Matrix v 6.20.2, if that helps.

Thanks again!


(Iain Simmons) #5

Hi @margaret.chatwin,

Unfortunately I think sorting is one of the ones that won’t take a custom GET variable.

I think in this case you’re better off leaving it hardcoded, since you have already selected the particular asset ID to nest, but if you did need a dynamic solution, you could swap the whole nested content container for a server-side JavaScript (SSJS) equivalent.

That in itself would get a bit more complicated, but let me know if that’s something you’re interested in.

Cheers,
iain


(Margaret Chatwin) #6

HI @isimmons,

Ah ok, thanks for confirming that. Hardcoding it is not the end of the world - just would’ve been nice to avoid that extra little step - but at least it works!

I think I’ll leave it at that for now, but it’s good to know that SSJS is a possibility in the future.

Thanks again,

Margaret