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 11-01-2013, 05:30 PM   #1
AnselmD
Zealot
AnselmD began at the beginning.
 
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
AnselmD is offline   Reply With Quote
Old 11-02-2013, 11:25 AM   #2
At_Libitum
Addict
At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.
 
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,'','',$)'|[|]: }
Attached Thumbnails
Click image for larger version

Name:	nozeros.png
Views:	224
Size:	3.1 KB
ID:	114504  

Last edited by At_Libitum; 11-02-2013 at 11:28 AM.
At_Libitum is offline   Reply With Quote
Advert
Old 11-02-2013, 04:50 PM   #3
AnselmD
Zealot
AnselmD began at the beginning.
 
Posts: 105
Karma: 10
Join Date: Oct 2013
Device: none
Quote:
Originally Posted by At_Libitum View Post
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,'','',$)'|[|]: }
Thank you, yes it works and i think i understand it. 1st format and then run cmp in template program mode and do the prefix, suffix.

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}
and i would like to have a seperator, e.g. a colon, if the series_index is zero.

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?
AnselmD is offline   Reply With Quote
Old 11-02-2013, 08:17 PM   #4
At_Libitum
Addict
At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.
 
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}
I'm sure the real template wizards can come up with a solution that doesn't need the double inclusion

Last edited by At_Libitum; 11-02-2013 at 08:19 PM.
At_Libitum is offline   Reply With Quote
Old 11-03-2013, 03:49 AM   #5
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: 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}
The template outputs nothing other than the title if there is no series. If there is a series, it outputs only the title if the series index is less than zero, a simple 'colon space' if there is a series but the series index is zero, and [nnnn.n]: if the series index is greater than zero.

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')
)
chaley is offline   Reply With Quote
Advert
Reply


Forum Jump

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


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


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