Quote:
Originally Posted by mtjj
I'm having some trouble with if statements in the template editor for Saving books to disk.
What I want is to handle three different cases:
If the custom column "Admin tags" (admin_tags) contains "#MAS" then
Code:
#MAS/{series}/{series_index:0>2s| - |}{title} ({authors})
Else, if the Series is not blank:
Code:
{author_sort[0]}/{authors}/{series}/{series_index:0>2s| - |}{title}
Else:
Code:
{author_sort[0]}/{authors}/{title}/{title}
This will hopefully give me:
[export folder]/#MAS/Doctor Who New Adventures/04 - Timewyrm Revalation (Paul Cornell).epub
[export folder]/C/Paul Cornell/The Severed Streets/01 - London Falling.epub
[export folder]/C/Paul Cornell/Chalk/Chalk.epub
(ideally the output would be as listed above, so the /C/ is from the author sort and the other outputs are from the non-sort fields, but I don't really care, if everything comes out with sort order, so it's /C/Cornell, Paul/Severed Streets, The/.... I'm also happy.)
I'm trying to setup a single export job that can be picked up by another program, that needs a folder by series (or, if a book is not part of a series, a folder per book). But it has a lot of trouble with multi-author series that end up in different author folders, so I will tag those manually, so they end up in the "#MAS" folder.
Looking at examples above, they seem to be written as programs. Can I put if statements in the simple template format, or I need to re-write it as a program?
Thanks in advance to anyone who can advise!
|
Yes, you must use General Program Mode to use if statements.
Here is an example ofwhat I think you want to do:
Code:
program:
if '^#MAS$' inlist $#admin_tags then
template('#MAS/{series}/{series_index:0>2s| - |}{title} ({authors})')
elif $series then
template('{author_sort[0]}/{authors}/{series}/{series_index:0>2s| - |}{title}')
else
template('{author_sort[0]}/{authors}/{title}/{title}')
fi
To head off one question: the value of an if statement is the value of the last statement executed inside the if, in the case the last template() call.
If you want $series and $title to use the non-sort values then change the tweak (Preferences / Tweaks) "Control formatting of title and series when used in templates (ID: save_template_title_series_sorting)". Set it to strictly_alphabetic.
FWIW: You have the ' - ' in the series_index portions of the templates in the wrong place. Your examples say they should go after the second '|' so you get the index, the dash, then the title. Example:
Code:
{series_index:0>2s|| - }