View Single Post
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: 12,449
Karma: 8012886
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