|
|
Thread Tools | Search this Thread |
04-29-2012, 11:44 PM | #1 |
Junior Member
Posts: 1
Karma: 10
Join Date: Apr 2012
Device: Kindle Touch
|
Error parsing templates when metadata fields have special characters like &, ' or ó
Am just playing around with templates so I can create a stand-alone library with a desired folder structure. Basically I would like to organize it by series if part of a series, else by authors. The template I am using is as below:
{series:'test($,eval('Series/{series}/{series_index:|| - }{title} ({authors})'),eval('Authors/{authors}/{title}'))'} To test it out, I used it as the template for a composite column that I display on the Calibre GUI. It appears to work as expected, except where there are some special characters in the title or authors, e.g. when the title contains an apostrophe or if there are multiple authors separated by & or if the author contains characters like ó. Not sure if there is a way to escape the field value when "eval"uating the template, so these special characters do not interfere with the template evaluation. Pardon me if this is a newbie question, which I readily admit to being :-). I searched the forums and on google, but could not come up with anything that could help me solve this problem. Would appreciate any help fixing the above template to obtain the desired result or other suggestions to achieve the same objectives. Thanks Last edited by sr2012; 04-30-2012 at 12:27 AM. Reason: General issue |
04-30-2012, 02:37 AM | #2 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
There are three problems in this template:
1) You should be using the "template" function, not the "eval" function. "Eval" substitutes template local variables, which your template doesn't use. "Template" substitutes book metadata. 2) As noted in the documentation for "template", in template program mode you must use "[[" for "{" and "]]" for "}". Otherwise you run into the subtemplate problem, which is what you are seeing. I added this note to the documentation for "eval". 3) For reasons that are not fixable with reasonable performance, you cannot use prefixes and suffixes (the "|prefix|suffix" notation) in the argument to "template" (or "eval") in template program mode. I have added this restriction to the documentation. The way to get around problems 2 and 3 is to use general program mode. The following GPM template implements the example you provided Code:
program: a = template('Series/{series}/{series_index:|| - }{title} ({authors})'); b = template('Authors/{authors}/{title}'); test(field('series'), a, b) |
Advert | |
|
Tags |
library management, metadata, special characters, template |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Too many authors with only 1 title | transmitthis | Library Management | 2 | 06-23-2011 10:16 AM |
conversion to FB2 error with & in title | tselling | Calibre | 2 | 01-07-2010 11:46 PM |
Error parsing attribute name? | seagull | Calibre | 1 | 01-01-2010 11:30 AM |
Calibre Author/Title parsing | sglinert | Calibre | 1 | 05-23-2008 10:18 AM |