@page title="Tips and Best Practices" keywords="tips, best practices"> <@sect title="Finding out the reasons of errors">
Use a log file (see: <@s>logFile@s>) as that will contain the full error stack trace. Also, if you are really lost, you may use temporary <@c>pp.warning@c>-s as a poor man's debugger: you can see if a certain line in the template is reached, also you can print the current values of variables.
@sect> <@sect title="Speeding up processing when you have many files">Some tricks:
FTL (FreeMarker Template Language) is not a general purpose programming language, just a template language. Implementing complex programming logic in it is cumbersome, and defeats the original purpose of templates: to be simple, almost the same as the output. To avoid this, pair BeanShell scripts with the problematic templates, and do the complex calculations in the script file, and then pass the results to the template for displaying. BeanShell is good in calculating data (and in whatever complex algorithms), FTL is good in displaying data. So you use the adequate languages for the subtasks. This can be implemented with the <@s>localData@s> setting and its <@c>bsh@c> function.
@sect> <@sect title="Showing information about something that will be generated further down">For example, you have to show a Table of Contents at the top of the page, but the list of headings is not known until the page generation reaches the bottom of the page. In this case, generate the section that contains the headings first, but capture the output in a variable with an assignment directive (as <@c><#assign <@r>var@r>><@r>...@r></#assign>@>). Then print the top of the page, and then the captured output. Check <@example 'capture' /> to see a working example.
@sect> @page>