11-01-2013, 05:30 PM | #1 |
Zealot
Posts: 105
Karma: 10
Join Date: Oct 2013
Device: none
|
Formatting Series in a user defined column. How?
Hi,
i have some difficulties using the template language in a user defined column. I defined a template to a used defined text column. So make it simple, i reduce this example to the part, which i can not solve. This one works, it formats the series index to 6.1f in square brackets. {series_index:0>6.1f|[|]: } Now i want to omit the output if the series index is zero (not empty but zero). I started with this one without formatting and without square brackets. {series_index:'cmp($,0,'','',$)'} How can i get the formatting in it? I tried different ways, but i always get template errors. Anyone who can help me? Best regards, Anselm |
11-02-2013, 11:25 AM | #2 |
Addict
Posts: 265
Karma: 724240
Join Date: Aug 2013
Device: KyBook
|
I've got no idea if this is the 'official' way but I got it to work using it like so
Code:
{series_index:0>6.1f:'cmp($,0,'','',$)'|[|]: } Last edited by At_Libitum; 11-02-2013 at 11:28 AM. |
Advert | |
|
11-02-2013, 04:50 PM | #3 | |
Zealot
Posts: 105
Karma: 10
Join Date: Oct 2013
Device: none
|
Quote:
I just expand this to something i would like to have (adding series and title): Code:
{series}{series_index:0>6.1f:'cmp($,0,'','',$)'|[|]: }{title} So i changed it to Code:
{series}{series_index:0>6.1f:'cmp($,0,'',': ',$)'|[|]: }{title} which does not work TEMPLATE ERROR format: type f requires a decimal (float) value, got :- I am mixing numbers and strings, which is not allowed. Any good idea? |
|
11-02-2013, 08:17 PM | #4 |
Addict
Posts: 265
Karma: 724240
Join Date: Aug 2013
Device: KyBook
|
Not sure if this is what you meant. I'm no template buff either but here's what I came up with. Seeing as the colon was the problem I took it out of there and made it a separate test. But for the life of me I can't get the space to stick other than putting it in front of the title field. It still seems to get swallowed when no series is present.
It just puts the title if there's no series, if there's a series and series index>0 it formats it with the leadzero and decimal in brackets, but if the index is zero it puts out nothing. And last if there's a series to begin with, regardless of index being zero or not, plant the colon. Code:
{series}{series_index:0>6.1f:'cmp($,0,'','',$)'|[|]}{series_index:test(:,)} {title} Last edited by At_Libitum; 11-02-2013 at 08:19 PM. |
11-03-2013, 03:49 AM | #5 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
It also isn't clear to me what output you expect in all cases. I took some guesses and came up with the following.
Code:
{series} {series_index:' test( field('series'), cmp($, 0, '', ': ', finish_formatting($, '0>6.1f', '[', ']: ')), '') '} {title} Although this template is in template program mode, I would probably use general program mode if I were doing it for myself. GPM can be easier to read and debug. For example, the following is equivalent to the above template Code:
program: series = field('series'); series_index = field('series_index'); strcat( series, test( series, cmp( series_index, 0, '', ': ', finish_formatting(series_index, '0>6.1f', '[', ']: ') ), '' ), field('title') ) |
Advert | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Old Thread] User Defined Column | Cpl Punishment | Calibre | 17 | 02-16-2014 01:43 AM |
Help Please - user defined USB problem | HeavyTZM | Library Management | 4 | 11-26-2011 09:06 PM |
default value for defined y/n column | bucsie | Calibre | 5 | 10-04-2010 10:08 AM |
User Defined Columns | jjansen | Calibre | 3 | 03-17-2010 05:33 PM |
User Defined Fonts | gr8npwrfl | Ectaco jetBook | 1 | 01-21-2010 08:35 AM |