![]() |
#1 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 126
Karma: 20236
Join Date: May 2014
Device: Kinde PW v1, Kobo H2O, Onyx Boox T68
|
conditionnal custom column
Greetings,
I am trying to build a custom column, which content must be different, depending on the series field, empty or not (for my kobo bookshelves). Here is an example : if {series} exists, i want : {author_sort} - {series} if {series} is empty, i want : {author_sort} Can you help me, please ? Thanks in advance ![]() |
![]() |
![]() |
![]() |
#2 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 126
Karma: 20236
Join Date: May 2014
Device: Kinde PW v1, Kobo H2O, Onyx Boox T68
|
Hi Myki, here is the solution ! (yes i love to talk to myself, even if i'm not always agree with myself
![]() Code:
{authors:'switch(count($, '&'), 1, $, list_item($, 0, '&'))'}{series:| - |} If {series} is not empty, the custom field will be feed with the first author, a "-", a space and the name of the serie. ex : Rowling, JK - Harry Potter ![]() (yes i love myself ![]() |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Code:
{author_sort}{series:| - |} EDIT: myki -- didn't see your post until I posted. But there really is no need to jump the gun and assume only the first author is wanted. ![]() Also, you might want to consider reducing your own template to: Code:
{authors:sublist(0,1,&)}{series:| - |} Code:
{authors:list_item(0,&)}{series:| - |} Last edited by eschwartz; 03-23-2015 at 07:09 PM. |
![]() |
![]() |
![]() |
#4 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 126
Karma: 20236
Join Date: May 2014
Device: Kinde PW v1, Kobo H2O, Onyx Boox T68
|
your code is clear and perfect, thank you very much eschwartz
![]() And to extract the firstname of the first author in author_sort, i use this : Code:
{author_sort:re((.*?)\,(.*?)( &|),\2)} |
![]() |
![]() |
![]() |
#5 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Well, it always gets the first (and middle) name of the last author...
Try this: Code:
{author_sort:re(^(.*?)\, (.*?)( & .*|$),\2)} ![]() |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 126
Karma: 20236
Join Date: May 2014
Device: Kinde PW v1, Kobo H2O, Onyx Boox T68
|
Thanks for your help, I like it clear and efficient
![]() I have (I hope) a last improvement to do : I need to make a custom field (#kobocollections), which content is feed by another custom field if not empty (#categorieperso), and a custom value if empty ({authors:sublist(0,1,&)}{series:| - |}). I succeeded by using : Code:
program: a = field('#categorieperso'); b = template('{authors:sublist(0,1,&)}{series:| - |}'); test(field('#categorieperso'), a, b) Code:
{#categorieperso:'ifempty($, template('{authors:sublist(0,1,&)}{series:| - |}'))'} Can you help me again, please ?? ![]() Last edited by myki; 03-25-2015 at 03:56 AM. |
![]() |
![]() |
![]() |
#7 | ||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
program: a = field('#categorieperso'); b = template('{authors:sublist(0,1,&)}{series:| - |}'); ifempty(a, b) Code:
program: ifempty( field('#enum2'), template('{authors:sublist(0,1,&)}{series:| - |}')) Quote:
|
||
![]() |
![]() |
![]() |
#8 |
Zealot
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 126
Karma: 20236
Join Date: May 2014
Device: Kinde PW v1, Kobo H2O, Onyx Boox T68
|
I have adopted your first purpose, thanks again
![]() Calibre is wonderful thanks to the author and to its community, thank you again for your help on this post and the others ! |
![]() |
![]() |
![]() |
#9 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
You don't strictly have to use GPM (when evaluating sub-templates), though, you *could* use TPM and substitute "[[" and "]]".
Granted, any such template is sufficiently complex enough to beg for GPM. ![]() |
![]() |
![]() |
![]() |
#10 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
<Technical> The template parser runs in two passes. The first, mostly controlled by the python 'format' library, extracts and parses { ... } template information. The second, mostly controlled by my code, extracts TPM functions from inside the program string using the GPM parser. The problem that arises is that the first parser sees the ':| - |' after the #series and connects it with the nearest opening brace ({), which when using [[ and ]] is the one in front of #categorieperso. The result is a mess, causing the parser to throw up its hands. If you leave the { and } around the series ({series:| - |}) then the parser gets it right, attaching the prefix and suffix to the right variable. Unfortunately, because this parser and evaluator run before the program parser, this sub-template is evaluated and replaced with the result. If that result contains a significant character such as a quote, comma, bracket, or bar then the resulting argument for the template function will be bogus. I have considered removing the [[ and ]] hack because the rules for successful use approach incomprehensible. ![]() </Technical> |
|
![]() |
![]() |
![]() |
#11 | ||
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Quote:
![]() Quote:
|
||
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Custom column returns value based on value of another custom column? | calvin-c | Calibre | 3 | 09-14-2013 02:24 PM |
Custom yes/no column built from long text column | Philantrop | Library Management | 7 | 03-23-2013 07:44 PM |
how to move value(s) of tag column to a custom made column | zoorakhan | Library Management | 0 | 12-08-2012 03:53 AM |
custom date column from two state column | Dopedangel | Library Management | 7 | 01-03-2012 08:20 AM |
Can custom book data be displayed in a custom column? | kiwidude | Development | 9 | 03-02-2011 05:35 AM |