View Single Post
Old 12-21-2011, 04:59 AM   #5
Ruskie_it
Fanatic
Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.
 
Posts: 538
Karma: 1000000
Join Date: Dec 2011
Location: Rome, Italy
Device: Kindle PW5, Kindle PW4, Kindle 4 NT
Thanks again.
Since I had a little spare time today at work, I had another go at it. Here is how I figured out how it could be, I'm posting this here in case anyone is interested:

{series}/{author_sort:'test(ifempty(field('series'),""),"", $)'}/{series_index:0>2s|| - }{title} - {authors}

The heart of what I was trying to do is this:

{author_sort:'test(ifempty(field('series'),""),"", $)'}

Here's the logic (I did not find relational operators, otherwise it might have been simpler):

So, if {series} is empty, calibre won't create {series} folder in the first instance. After that, if series is empty, the function

ifempty(field('series'),"")

will return an empty string. This string will be thrown at the test function it is called within:

test(FUNCTION,"",$)

If the value of the function is "" (that is if, and only if, the {series} field is empty, the function test will output the value of the author field, $; if the value is not empty, then test will return an empty value.

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)

If anyone has experience in coding, please correct or confirm... thank you!!!

Rus

Last edited by Ruskie_it; 12-21-2011 at 10:22 AM. Reason: wrong order of the test parameters
Ruskie_it is offline   Reply With Quote