View Single Post
Old 10-04-2013, 05:19 AM   #5
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,462
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by BeeTee-Ess View Post
Hello Adoby...

Please bear with me again. That is the first time I have used templates.

I am trying to extend the template above to replace the comma in the author_sort field with a semi-colon, so that Smith, Bill becomes Smith; Bill.

I assume that I need to use the re function, and came up with:

{re({author_sort:list_item(0,&)},,,}

but I expect I shall need to use some sort of escape character to distinguish the pattern argument comma from the separator commas between the function arguments.

Then, I am uncertain how I should combine the two functions, once I have expressed the re function correctly.

Just applying the initial template you provided has shown me what a time-saver they can be, and I want to become more fluent in their use.
You can't nest template functions when using single function mode, which is what is used in the template Adoby gave you. You must use one of the other two modes, template program mode or general program mode. Which you pick depends on what you are trying to do, where the template will be used, and the complexity of the template.

I would use general program mode because this template will be used in a custom column. GPM templates used in custom columns are compiled and run significantly faster than the other kinds, which is important when browsing large libraries containing such columns.

A GPM template to do what you want is:
Code:
program: 
	asort = list_item(field('author_sort'), 0, '&');
	re(asort, ',', ';')
For completeness, the template in TPM is
Code:
{author_sort:'re(list_item($, 0, '&'), ',', ';')'}
chaley is offline   Reply With Quote