ddekany edited a comment on pull request #67:
URL: https://github.com/apache/freemarker/pull/67#issuecomment-633016699


   The idea of `#include` was simply to behave as if you have copy-pasted the 
other template there. That's a very simple concept to understand for the users. 
But it becomes unwieldy if you build a complex systems of templates (which I 
don't think was expected by the authors originally). So namespaces and 
`#import` was added. Even with the "only include once" feature, the reusable 
files will have no own namespace, so they aren't well separated, which can be a 
maintenance problem. 
   
   I don't think we should support this pattern, which we don't want users to 
follow, in the core (which is already quite bloated). How about you create a 
`TemplateDirectiveModel` , and use it like `<@includeOnlyOnce>... your current 
template content comes here ...</@includeOnlyOnce>`? It could get the template 
name from the `Environment`.
   
   Some notes, both for the current implementation, and for the possible 
`includeOnlyOnce` implementation:
   
   * You should suppress output printed inside the template that's "only 
included once". Surely you don't want that, as it should be transparent if 
something is included for the first time or not.
   
   * "Only once" should mean once per namespace, and not once per `Environment`.
   
   * Deciding based on `Template` object identity if something was already ran 
won't be good enough, because `Configuration.getTemplate` might returns a 
different instance for the same name if the cache behind was evicted (also 
there's actually no hard guarantee that it caches at all). You have to use the 
full name of the included template instead.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to