View Single Post
Old 04-30-2012, 02:37 AM   #2
chaley
Grand Sorcerer
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: 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)
As a side benefit, this implementation will have better performance because GPM templates are compiled into python instead of interpreted on each use.
chaley is offline   Reply With Quote