Debugging Freemarker

The Freemarker language provides a number of useful debugging tools. Titania Delivery adds to these with a number of mechanisms for analyzing and debugging the behavior of your templates.

Use <#attempt>/<#recover>

Wrapping a section of your template in <#attempt> allows you to handle errors that occur yourself, instead of having the page fail to render entirely. The error will be encapsulated in the built-in .error variable.

<#attempt>
<#-- Risky code here -->
<#recover>
<#-- Error handling here; the error is in the .error variable -->
<pre>${.error?html}</pre>
</#attempt>

Set the ?ftldebug URL parameter

When you add the ?ftldebug parameter to a Titania Delivery portal URL, HTML comments will be inserted around all template <#include> directives. In addition, boundaries around content laid out using the special directives will also be marked. This can significanly help in identifying where the Feemarker code that generated a part of the page is managed.

<!-- START TEMPLATE "/pages/viewer.ftl" -->
<!-- START TEMPLATE "/pages/masters/mainLaout.ftl" -->
<!DOCTYPE html>
<html>
<head>
  <!-- START REGION "htmlHead" from "/pages/viewer.ftl" -->
  <title>Topic Title</title>
  <!-- END REGION "htmlHead" from "/pages/viewer.ftl" -->
</head>
<body>
  <!-- START REGION "body" from "/pages/viewer.ftl" -->
    <!-- START TEMPLATE "/pages/masters/modules/layout.ftl" -->
      Navbar Content Here
    <!-- END TEMPLATE "/pages/masters/modules/layout.ftl" -->
    Contents of the page here.
  <!-- END REGION "body" from "/pages/viewer.ftl" -->
</body>
</html>
<!-- END TEMPLATE "/pages/masters/mainLayout.ftl" -->
<!-- END TEMPLATE "/pages/viewer.ftl" -->