Features / Usability

Features / Usability

How to sort results (dates) from a dynamic tracker field in smarty

posts: 8406 Israel

I have trackeritems displayed in a plugin List using smarty template.

One of the field is a dynamic list field and it display a list of dates in unsorted order and that is very disturbing for users.

As there is no option in the DIL to display the results in a sorted order I wonder if we have a modifier or a function for this.

The results {$orderrow.holydaysDay} value is:

holydaysDays => "17-10-2019<br>16-10-2019<br>15-10-2019"

From here I tried to sort in an inner foreach.
But couldn’t figure the right parameters or maybe this doesn’t exist in Tiki

{foreach $orderrow.holydaysDays|sortby ???  as $date}

I also look for a javascript to split and sort the value... But it seem pretty prehistorical to go that way (but may be this is the only way ?)

posts: 126754 United Kingdom

Hi B

I think you'll need to use the PHP sort function https://www.php.net/sort

You'll need to add it as an allowed php function in the security control panel, and the use it something like (totally untested)

Hmm, but you'll need to turn the string into an array first... try

{$dates = '<br>'|explode:$orderrow.holydaysDays}

However... you will also have to change the date format so it sorts correctly, to YYYY-MM-DD - hmm, must be a better way eek