Menu

#145 Template settings lost in complex nesting structure

2.3.22
closed-fixed
nobody
None
5
2015-02-28
2006-08-25
No

In a complex nesting structure, configuration settings
in the a template can disappear.

In my sample, I have a template which calls a macro in
a library, and then nests another macro call to an
include file of the library within the first macro
call. So, we have:

=================================================
file structure
=================================================
template.ftl - the primary template
lib.ftl - imported into template.ftl
include.ftl - included by lib.ftl

=================================================
macro call stack
=================================================
template.ftl - template calls macro_1
lib.ftl - executes macro_1
template.ftl - nested call to macro_2
include.ftl - macro_2 calls macro_3
lib.ftl - macro_3 *LOSES SETTINGS*
template.ftl - nested, context regained!

Source files attached that duplicate the problem,
run FreemarkTest class and check output.txt for the
obvious loss of settings.

Discussion

  • Paul Galbraith

    Paul Galbraith - 2006-08-25

    eclipse project w/source

     
  • Paul Galbraith

    Paul Galbraith - 2006-08-25

    template.ftl

     
  • Paul Galbraith

    Paul Galbraith - 2006-08-25

    lib.ftl

     
  • Paul Galbraith

    Paul Galbraith - 2006-08-25

    test.ftl

     
  • Paul Galbraith

    Paul Galbraith - 2006-08-25

    FreemarkerTest.java

     
  • Paul Galbraith

    Paul Galbraith - 2006-08-25

    output.txt

     
  • Paul Galbraith

    Paul Galbraith - 2006-08-25

    Logged In: YES
    user_id=202975

    This is occuring in Freemarker 2.3.8

     
  • Dániel Dékány

    • status: open --> open-accepted
    • Group: --> undecided
     
  • Dániel Dékány

    • status: open-accepted --> open-fixed
    • Group: undecided --> 2.3.22
     
  • Dániel Dékány

    Using Configuration cfg = new Configuration(Configuration.VERSION_2_3_22) in the attached example will fix this.

    From the version history:
    Bug fixed [145]: Active only with incompatible_improvements set to 2.3.22 (or higher): #include and #nested doesn't change the parent Template (see Configurable.getParent()) of the Environment anymore to the Template that's included or where #nested returns to. Thus, the parent of Environment will be now always the main Template. (The main Template is the Template whose process or createProcessingEnvironment method was called to initiate the output generation.) Note all this only matters if you have set settings directly on Template objects, and almost nobody does that. Also note that macro calls have never changed the Environment parent to the Template that contains the macro definition, so there's no change there now.

     
  • Dániel Dékány

    • Status: open-fixed --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB