Does freemarker support the entire variable in the data model?

I want to see all the variables in the freemarker data model, just like the struts2 debug tag to show a stack of values.

Is there a way for freemarker to do this?

+6
freemarker
source share
1 answer

There is no one-stop solution for this, but you can try

 <#list .data_model?keys as key> ${key} </#list> 

This works if the data model is a regular Map or JavaBean, but for more complex data models this applies to the implementation of the data model, if it supports ?keys , and if it really returns everything.

You also have variables that you set in the templates, which can be listed as above, instead of .data_model use .globals , .namespace (which means the current template namespace) and .locals .

You can also have shared Configuration -level variables, and there is no way to list them only from FTL (you can write a custom TemplateMethodModel for it that reads Configuration.getSharedVariableNames() , although it calls it from the template).

Of course, ideally, FreeMarker should have a directive <#show_variables> or something else that does everything possible to show all this ... but, unfortunately, this is not yet.

+13
source share

All Articles