1

I'm using freemarker to generate files and I'm struggling with the templateExeptionHandler part. I have variables in my template that don't have to be replaced (if they are not present in the data-model). I don't like to put these variables inside my data-model with the same value (can't get it to work either) and I know I can 'escape' variables in the template itself but I don't really like that solution.

MyTemplateExceptionHandler looks as follows:

class MyTemplateExceptionHandler implements TemplateExceptionHandler {
public void handleTemplateException(TemplateException te, Environment env, Writer out) throws TemplateException {
  try {
    out.write("${" + te.getBlamedExpressionString() + "}");
  } catch (IOException e) {
    throw new TemplateException("Failed to print error message. Cause: " + e, env);
  }
}

}

The problem is that once I'm parsing variables in the form of:

${workflow.input.myVariable}

the result in my new generated file is showing only the first part of this variable:

${workflow}

Any thoughts on how I can get the full variable back and returned in my generated file?

R. Sluiter
  • 162
  • 1
  • 1
  • 13

1 Answers1

1

That use case is not supported, as of 2.3.27 at least. It's not even clear how it should work, like, what if the missing variable is a parameter to a directive? Certainly it could be solved for the case of ${} only (even then, only when it appears outside a string literal), but I'm not sure if that addresses the need, or it just lures uses into using it and then they hit a wall later on with a directive parameter... (Or, another tricky case, what's with ${thisIsMissing + thisExists}? I guess it should become to something like ${thisIsMissing + 123}... so doing this right can complicate the core quite much.)

ddekany
  • 29,656
  • 4
  • 57
  • 64