Tips and Best Practices

    
  Prev  Next  Contents  Home
 

Page contents

Finding out the reasons of errors

Error messages (especially FreeMarker error messages) are often not too helpful or simply bad, and it is hard to find out what the actual problem is. But if you use a log file (see: logFile), that will contain the full error stack trace. You often find helpful information there, such as the FTL stack strace. Also, if you are really lost, you may use temporary pp.warning-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.

Speeding up processing when you have many files

There are 3 main tricks:

Prevent too much programming logic in templates

Some of your FreeMarker templates can become so complicated, that they are rather programs than templates. Implementing complex programming logic in FTL (FreeMarker Template Language) is not only cumbersome, but defeats the original purpose of templates: to be simple, almost the same as the output.

To prevent 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 localData setting and its bsh function.

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 <#local var>...</#local>). Then print the top of the page, and then the captured output. Check <FMPP>/docs/examples/capture to see a working example.

Prev  Next  Contents  Home      Report bug   Generated on Dec 16, 2007 10:12 PM GMT
For FMPP version 0.9.13
SourceForge Logo  Powered by FreeMarker