tags:

views:

214

answers:

1

We are trying to build a system in freemarker where extension files can be optionally added to replace blocks of the standard template.

We have gotten to this point

<#attempt>
    <#include "extension.ftl">
<#recover>
    Standard output
</#attempt>

So - if the extension.ftl file exists it will be used otherwise the part inside of the recover block is output.

The problem with this is that freemarker always logs the error that caused the recover block to trigger.

So we need one of two things:

  1. Don't call the include if the file doesn't exist - thus the need to check for file existence.

-OR-

  1. A way to prevent the logging of the error inside the recover block without changing the logging to prevent ALL freemarker errors from showing up.
A: 

Try this. I needed the same stuff and got this.

<#assign objectConstructor = "freemarker.template.utility.ObjectConstructor"?new()>
<#assign file = objectConstructor("java.io.File", "somefile")> 
<#if file.exists()>
File exists
<#else>
File do not exists
</#if>
Amit