Tips and Best Practices |
| |
Page contents
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.
There are 3 main tricks:
skipUnchanged
setting. For most applications you can safely use it with the static
value, and it speeds up things a lot if you have many images or other static files.
quiet
setting to true
or reallyQuiet
, or set echoFormat
to terse
for the command-line tool. Surprising enough, some terminals (at least Windows 2000 command line window) scrolls screen slowly, so FMPP has to wait until it can print the next line to the screen, and this can even double the total session time. Funny...
sources
setting.
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.
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.
|
||