View Single Post
Old 07-06-2012, 10:22 AM   #285
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: 4,707
Karma: 800144
Join Date: Jan 2010
Location: France
Device: Many android devices
The easiest way to handle this situation is to use a prefix in the template. The prefix is added only if the field is not empty. For example, warning would be
Code:
{#warnings:|Warning: |}
and genre would be
Code:
{#genre:|Genre: |}
for more explanation, see Advanced formatting in the user manual.

Of course, it could be done with the test function. For example, the following examples in template program mode and general program mode work. However, unless the computation is more complicated than strcat, it isn't worth the trouble.
Code:
{#warnings:'test($, strcat('Warning: ', $), '')'}
or
Code:
program:
	v = field('#warnings');
	test(v, strcat('Warning: ', v), '')
chaley is offline   Reply With Quote