Quote:
Originally Posted by theducks
I just got around to trying this feature (been doing a pick from 2 patterns)
Code:
{series:switch("","00noseries"/{author_sort[0]}_authors/{authors}/{title}_{id}_{title}-{authors},{series[0]}-series/{series}/{series_index:0>2s}-{title}_{id}_{authors})}
When I save a series I get the second (else) part.
When the series is blank, the attached file (OPF part of the pair. Avoiding copyright issues  ) name is generated (no folder path,either)
BTW,I tries without the quotes around 00noseries first.
did I miss something?
TNX
|
You missed a lot.
The template language supports three modes: single function, template program, and general program. Your template is using single function syntax, which (unfortunately for your example) does not support quoted strings or non-constant arguments (arguments that require further evaluation). In addition, no mode supports implicit string concatenation, which you are using after "00noseries". Finally, the regular expression "" (in the switch) will look for literal 2 quotes and match anything, which isn't what you want. You would need something like ^$, or "^$" in one of the other two modes.
You could use template program mode and fix all of this, but with something as complex as you have I would instead suggest that you use general program mode. In that mode, the program would be:
Code:
program:
test( field('series'),
template("{series[0]}-series/{series}/{series_index:0>2s}-{title}_{id}_{authors}"),
template("00noseries/{author_sort[0]}_authors/{authors}/{title}_{id}_{title}-{authors}")
)
For completeness, note that the although the above program works, it prints some exception messages. The reason is that the second argument to test, the first template line, is evaluated but not used. In that context, {series[0]} is invalid. A cleaner implementation, one with no exceptions, would be:
Code:
program:
test( field('series'),
strcat(
substr(field('series'), 0, 1),
template("-series/{series}/{series_index:0>2s}-{title}_{id}_{authors}")
),
template("00noseries/{author_sort[0]}_authors/{authors}/{title}_{id}_{title}-{authors}")
)