VERSION_2_3_22 incompatible improvements break .template_name
Generates text that depends on changing data (like dynamic HTML).
Brought to you by:
revusky
When setting the incompatible improvements to 2.3.22, .template_name stops to working correctly. It will no longer return the correct value.
.template_name is documented to return "The name of the current template (available since FreeMarker 2.3.14).", but it does return Environment.getTemplate().getName(), which is "broken" by incompatible improvements 2.3.22.
.template_name should rater return Environment.getCurrentNamespace().getTemplate().getName().
If future versions of Freemarker can no longer support .template_name it should at least be documented.
So, with
incompatible_improvements2.3.22,.template_namealways return the name of the main template. Earlier it did some erratic thing, but surely it happened to return the expected name inside an#include-d template. And frankly, a haven't realized thatEnvironment.getTemplate()was exposed through a special variable, because this way it was indeed a too backward incompatible change for a micro version "incomplatible improvement". Sadly, nobody has brought this up during the RC period.Using
Environment.getCurrentNamespace().getTemplate().getName()won't solve this, because exactly when you#includeanother template, the current namespace won't change.As of the future, it will be possible to return both the main template name and the current template name (this time correctly). Then
template_namewill have to be deprecated and.main_template_nameand.current_template_namewill have to be added. I will see how can I fit that in into 2.3.23.(I have updated the JavaDoc to document that
.template_nameis affected: http://freemarker.org/docs/api/freemarker/template/Configuration.html#Configuration-freemarker.template.Version-)This is now fixed on GitHub 2.3 and 2.3-gae branches. Setting incompatible_improvements to 2.3.23 restores the backward compatible behavior of
.template_name. In additionally, there are two new special variables:.current_template_nameand.main_template_name. Unlike.template_name, these work with macro calls as expected.