Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 04-04-2021, 09:46 PM   #1
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,973
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Template: Prioritizing an item in sublists

I have this template for display of two columns in Kobo subtitles and Generate Covers:
Code:
{#taglike:'sublist(list_sort($, 0, ','), 0,1,',')'}  | {#anothercolumn}
Is there a way to make it so that if a specific value is present in #taglike, it is prioritized and appears instead of the first sorted one?

I see in the documentation about indexes, but that seems to be about what order it is in rather than a specific value.

e.g. if 'abc, bar, foo' appears it currently shows 'abc.'
I want to prioritize 'bar' so that it appears instead even though it is not first.
But 'bar' may not always be the second item in the list, e.g. 'aaa, aaaaaaaah, ahhhhhhhhh!!!, bar' or 'bar, random screaming'

I am thinking maybe sublists won't work for this, but something like list_re.

Context: The template is for displaying fanfic information. I want it to show 'Crossovers' if that value appears in #fanficcat.


Last edited by ownedbycats; 04-05-2021 at 01:58 AM.
ownedbycats is offline   Reply With Quote
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,447
Karma: 8012886
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
Advert
Old 04-05-2021, 11:55 AM   #3
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,973
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Code:
{#fanficcat:'list_contains($, ',', '^Crossover$', 'Crossover', sublist(list_sort($, 0, ','), 0, 1, ','))'}
works thank you
ownedbycats is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Template: saving template tester when restarting Calibre ownedbycats Library Management 14 03-29-2021 05:57 PM
Template: Converting a search & replace into a template ownedbycats Library Management 11 03-26-2021 04:32 AM
Using built-in template functions in a custom template function ilovejedd Library Management 4 01-28-2018 12:20 PM
Lists and sublists from ePub to azw3 draknan Conversion 2 12-25-2012 11:40 AM


All times are GMT -4. The time now is 12:28 AM.


MobileRead.com is a privately owned, operated and funded community.