View Single Post
Old 10-22-2011, 01:55 AM   #2
chaley
"chaley", not "charley"
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 5,626
Karma: 857074
Join Date: Jan 2010
Location: France
Device: Many android devices
Quote:
Originally Posted by uli View Post
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}'.
chaley is offline   Reply With Quote