View Single Post
Old 03-13-2012, 01:37 AM   #4
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: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Backi View Post
Could you confirm the malfunction I encountered using fields in prefix/suffix?

This template (just an example) works on books with and without series/series_index:
Code:
{series:|{isbn}|}{title}
These surprisingly don't work on books without series/series_index:
Code:
{series_index:|{isbn}|}{title}
{series_index:||{isbn}}{title}
It says in the single-function section of the manual: "All arguments must be constants; there is no sub-evaluation." Your template is using sub-evaluation because "{isbn}" is inside the series_index template expression.

The use of template expressions within template expressions is highly unreliable. I consider it a bug that it works at all, and would take it out except that doing so would cause the people for whom it works to yell very loudly. You have hit one of the problems -- expecting { ... } to nest. There are cases where they do not, one of which is references to series_index in save_to_disk templates. In the failure case a { is paired with the nearest }, not with the matching nested }. In other words, the { in front of "series_index" is matched against the } following "isbn", not against the one following the '|' character. The other common failure case occurs when the value being inserted contains a template special character such as '|', '{', '}', or sometimes ','.

You can express the equivalent of {series_index:|{isbn}|}{title} without nesting by using the following "template program mode" template.
Code:
{series_index:'test($, strcat(field('isbn'), $), '')'}{title}
For completeness, an equivalent template in general program mode is
Code:
program: 
	s = field('series_index');
	strcat(test(s, strcat(field('isbn'), s), ''), field('title'))
chaley is offline   Reply With Quote