View Single Post
Old 04-05-2021, 09:12 AM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,476
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
I would do this, assuming that there is only one priority item
Code:
{#genre:'list_contains($, ',', '^bar$', 'bar', sublist(list_sort($, 0, ','), 0, 1, ','))'}
If there can be more than one priority item I would use this as a stored template named list_priority_item
Code:
program:
	arguments(lst='No list argument given', items='');
	r = '';
	for l in items:
		if !r then
			r = str_in_list(lst, ',', l, l, '')
		fi
	rof;
	if !r then
		r = sublist(list_sort(lst, 0, ','), 0, 1, ',')
	fi;
	r
and call it like this:
Code:
{#genre:'list_priority_item($, 'Completed, Bar')'}
NB 1: calling stored templates from TPM is currently broken running from source. I will submit a fix soon.

NB 2: the loop in the stored template is a bit strange because the template language doesn't have a "break" statement.
chaley is offline   Reply With Quote