View Single Post
Old 12-21-2011, 01:12 PM   #9
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,476
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Glad you found template program mode!
Quote:
Originally Posted by Ruskie_it View Post
Here's the logic (I did not find relational operators, otherwise it might have been simpler):
The strcmp function provides comparison relationals. The test function provides equality relationals.
Quote:
Therefore, when {series} has a value the whole template will be:

series_name/""/book_title (and calibre will convert it to series_name/book_title)

When {series} has not a value the template will be:

""/author_name/book_title (and calibre, I expect, will convert it to author_name/book_title)
I assume that the above is in effect a requirements statement.

First, the /""/ will be converted to //, which will convert to /. As such, there isn't much point in generating it, although it doesn't hurt anything. Second, the test function can be used to test for != '', which eliminates the need for the subfunction by directly testing if series is not empty.

Combining the above with my understanding of your requirements, I think that this template satisfies your requirements.
Code:
{series:'test($, $, field('author_sort'))'}/{series_index:0>2s|| - }{title} - {authors}
chaley is offline   Reply With Quote