View Single Post
Old 04-01-2022, 01:34 PM   #1
sylvandale
Junior Member
sylvandale began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Apr 2022
Device: none
Using IF THEN ELSE in a Calibre Save Template

Hi. I'm hoping for some help please in configuring my Calibre Save Template, and using IF THEN ELSE logic.

I have a custom 'Genre' hierarchical column to organise everything in my library. I got this idea from here many years ago I think, so I assume people will know the kind of thing. Examples of the structure are e.g.
fiction
fiction.crime
fiction.thriller
fiction.thriller.historical
travel
travel.usa
travel.usa.ca
etc.

For a long time I have happily used a nice template, also taken from this forum (thanks!), which breaks down the genre into folders and subfolders based on the "." separator. This is the argument:

"{#genre:'re_group($,"([^.]+)\.","[[$]]/")'}/{authors}/{series}/{title} - {authors}"

So e.g. John Grisham's Camino Winds, with Genre 'Fiction.Thriller' is sorted to 'Fiction/Thriller/John Grisham/Camino Winds - John Grisham'. [There is also an optional "Series" subfolder level, if the series field is populated.]

However, I don't pretend to understand this syntax properly. It just works and I'm very grateful.

What I have realised is that for all Fiction books I want to have the {authors} level subfolder, but for all other types of books I want a sort which does not use that subfolder. With Fiction, I tend to know what author I am looking for, but with other types that's not usually the case.

So, in simple terms, what I think I am after is something like:

IF
genre is fiction.*
THEN
{#genre:'re_group($,"([^.]+)\.","[[$]]/")'}/{authors}/{series}/{title} - {authors}
ELSE
{#genre:'re_group($,"([^.]+)\.","[[$]]/")'}/{series}/{title} - {authors}

The '*' above is meant to be the usual wildcard expression, as there may be no additional genre sub-categories or one sub-category or two or more.

Can anybody help put that into Calibre-speak please?

Many thanks
sylvandale is offline   Reply With Quote