Quote:
Originally Posted by uli
I'd like the plugboard to use a different formatting when the series is Star Wars or Star Trek. So I created the following, everything works except if the title contains a comma or a parenthesis.
The calibre template guide mentions you need to escape these. How can I escape a field value?
Code:
{series:contains(Star Wars|Star Trek, {title}, {series}{series_index:0>2s| - | - }{title})}
|
Using template expressions inside template expressions has lots of problems. I consider it a bug that it works at all, but if I 'fixed' it I would annoy too many people. To be precise, the templates act as macros, inserting the text from the sub-evaluation then evaluating the enclosing phrase. If the sub-evaluation results in characters that are significant, then evaluating the enclosing phrase will fail.
What you should use is general program mode (see the manual) so you have control over what is evaluated, in what context. This mode permits embedding arbitrary templates as function values. For example, the above template would be written
Code:
program: contains(field('series'), 'Star Wars|Star Trek', field('title'), template('{series}{series_index:0>2s| - | - }{title}'))
This expression says that if the series field matches the regexp 'Star Wars|Star Trek' then return the title field, otherwise return the results of evaluating the template '{series}{series_index:0>2s| - | - }{title}'.