views:

158

answers:

1

I'm not at all sure that this is even a solvable problem, but supposing that I have a freemarker template, I'd like to be able to ask the template what variables it uses.

For my purposes, we can assume that the freemarker template is very simple - just "root level" entries (the model for such a template could be a simple Map). In other words, I don't need to handle templates that call for nested structures, etc.

A: 

This is probably late, but in case anyone else encountered this problem : you can use 'data_model' and 'globals' to inspect the model - data_model will only contain values provided by the model while globals will also contain any variables defined in the template. You need to prepend the special variables with a dot - so to access globals, use ${.globals}

For other special variables see http://freemarker.sourceforge.net/docs/ref_specvar.html

Jacek Lach
Actually, I'd like to get the list of variables in the template in my Java code. I'd like to be able to do something like:Template t;....List<Variable> = t.getReferenceVariables();
Jared
http://freemarker.org/docs/api/freemarker/template/Template.html#getRootTreeNode()gives you a hashtable of the model
Jacek Lach