How to implement path resolution when a template has already been submitted to Freemerker for rendering?

I am working on the release of WW-4145 in Apache Struts 2 to extend the Struts tags written with FreeMarker. The problem is how to resolve the path after MultiTemplateLoader has already resolved the path. Or, in other words, if the proposed solution is effective?

 <#macro includeThemeTemplate templateName> <#list parameters.themeHierarchy as theme> <#attempt> <#include "/${parameters.templateDir}/${theme}/${templateName}" /> <#break/> <#recover> </#attempt> </#list> <#-- Cause an exception intentionally which will have the top most theme --> <#include "/${parameters.templateDir}/${parameters.themeHierarchy[0]}/${templateName}" /> </#macro> 

and use in tag:

 <@includeThemeTemplate "controlheader.ftl"/> <#include "/${parameters.templateDir}/simple/checkboxlist.ftl" /> <@includeThemeTemplate "controlfooter.ftl"/> 
+4
source share
1 answer

I see no problems with it, since FreeMarker caches failed template checks (this means that this should not generate too much I / O, because the update delay is not too small). However, for framework-level content, you can use Java instead, as it is faster and often more convenient. The Java equivalent of #include is freemarker.core.Environment.include . To get an Environment object, you can use Environment.getCurrentEnvironment() (or if you use TemplateDirectiveModel , which will receive it as a parameter).

0
source

Source: https://habr.com/ru/post/1494268/


All Articles