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 01-16-2021, 05:08 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,974
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Template: Show only first value in a taglike

I have this template in KoboTouchExtended's subtitle field:

Code:
program:
	if field('#serieslike') then
		 template('{#serieslike} #{#serieslike_index:0>2s}')
	else
		if field('#taglike') then
			template('{#taglike} | {#enum}')
		fi
	fi
(For context, #serieslike is for reading lists, #taglike is fanfic category, and #enum is fanfic status.)

This works as expected. However, I noticed books with multiple values in #taglike tend to cause the subtitle length to overflow on my Kobo. So I'd like it to just display the first value. How do I do that?


Last edited by ownedbycats; 01-16-2021 at 05:12 PM.
ownedbycats is offline   Reply With Quote
Old 01-16-2021, 05:32 PM   #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
Use
Code:
{#taglike:sublist(0,1,\,)}
Note that 'first item' might be a rather loose concept. I don't remember if the list is sorted.
chaley is offline   Reply With Quote
Advert
Old 01-16-2021, 05:41 PM   #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,974
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I noticed that in Edit Metadata and the book details they appear in alphabetical order, though that might be FanFicFare's doing. Thank you!
ownedbycats is offline   Reply With Quote
Old 01-16-2021, 06:00 PM   #4
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
Quote:
Originally Posted by ownedbycats View Post
I noticed that in Edit Metadata and the book details they appear in alphabetical order, though that might be FanFicFare's doing. Thank you!
Multiple value fields except authors are sorted when they are displayed.

If it turns out the values are not sorted and if it matters then this TPM template takes care of it
Code:
{#taglike:'sublist(list_sort($, 0, ','), 0,1,',')'}
chaley is offline   Reply With Quote
Old 01-16-2021, 08:25 PM   #5
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Quote:
Originally Posted by chaley View Post
Multiple value fields except authors are sorted when they are displayed.

If it turns out the values are not sorted and if it matters then this TPM template takes care of it
Code:
{#taglike:'sublist(list_sort($, 0, ','), 0,1,',')'}
Calibre doesn't sort them except at display time. Editing the metadata can cause a sort. And some plugins, such as FFF sort tags and possibly other tag-like fields.

I'm not a fan of this, and have removed the sorting of tags from all the places in calibre that sorts them that I could find. If I ever get around to rewriting the tag editor to allow ordering, I might see about adding it as a tweak.
davidfor is offline   Reply With Quote
Advert
Old 01-16-2021, 09:00 PM   #6
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,974
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Code:
program:
	if field('#readorder') then
		 template('Reading List: {#readorder} #{#readorder_index:0>2s}')
	else
		if field('#fanficcat') then
			template('{#fanficcat:'sublist(list_sort($, 0, ','), 0,1,',')'} | {#fanficstatus}')
		fi
	fi
Gives me a "Missing closing parenthesis near 'sublist'" error. I tried adding one in a few places where I thought they might belong but it didn't go away. did I make a mistake of placing it?

Last edited by ownedbycats; 01-16-2021 at 09:05 PM.
ownedbycats is offline   Reply With Quote
Old 01-17-2021, 06:51 AM   #7
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
Quote:
Originally Posted by ownedbycats View Post
Code:
program:
	if field('#readorder') then
		 template('Reading List: {#readorder} #{#readorder_index:0>2s}')
	else
		if field('#fanficcat') then
			template('{#fanficcat:'sublist(list_sort($, 0, ','), 0,1,',')'} | {#fanficstatus}')
		fi
	fi
Gives me a "Missing closing parenthesis near 'sublist'" error. I tried adding one in a few places where I thought they might belong but it didn't go away. did I make a mistake of placing it?
Mixing TPM and GPM can lead to very strange errors because of quote matching. In your case the single quote after template( matches the quote after the colon, messing up the expression. To fix it you must use a combination of single and double quotes and ensure that the quotes balance correctly. In your case change the first and the last single quote to double quotes, giving you
Code:
template("{#fanficcat:'sublist(list_sort($, 0, ','), 0,1,',')'} | {#fanficstatus}")
I recommend that you don't intermix the two language forms. Instead of using "template" with TPM, construct the result yourself. For example (and using columns I have),
Code:
strcat(sublist(list_sort(field('#genre'), 0, ','), 0,1,','), ' | ', field('author'))
Not only is this safer, it is significantly faster. If your template uses prefixes and suffixes then use the finish_formatting() function.
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to show tag browser nepentanova Calibre 5 03-26-2019 05:59 PM
How to show books with only 1 tag? Dynamic tag or virtual library? cd2013 Calibre 4 03-01-2019 06:41 PM
Show Category in Tag Browser MerlinMama Calibre 4 02-01-2016 11:11 AM
I want Calibre 64bit to only show the tag selected hola!claude Library Management 3 12-22-2014 05:14 AM
template: if one of the tag is something... maybe contains or in_list functions fxp33 Calibre 4 07-19-2014 05:18 AM


All times are GMT -4. The time now is 08:17 AM.


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