Re: Nested Java directives - best practice on how to make values available to inner directive?
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Friday, February 1, 2008, 9:56:18 AM, Alistair Israel wrote: > On Jan 31, 2008 6:16 PM, Daniel Dekany <[email protected]> wrote: > >> Anyway, what you are looking for is >> called "parent-child communication" or "parent-children communication" >> on this list. But this feature was only added in 2.4, which is >> unreleased and unstable. > > Thanks. That's pretty much what I'm looking for, exactly. Can't wait > for 2.4, then. > > >> They won't be (unless the Spring guys did some big trick...), since a >> shared variable is always a top-level variable, for technical reasons. > > So shared variables are always top-level variables, got it. I guess > the segue question is how do I load custom Java directives at > Configuration time? > > I mean, what's the equivalent of > Configuration.addAutoInclude("mynamespace", "mymacros.ftl") for custom > Java directives? It should be the freemarker.core.Environment.importLib(String templateName, String namespace) method. However, it can only be called on tempalte-execution-time (or, right before that), as you can see from the Environment. Outside Environment-s it would be tricky to load an FTL "macro library", as some macros may expect to be in the runtime environment that the "macro library" template creates. So in the generic case they can't just be tear out from the template, and put into the shared variable set or something. It's the other way around as you seem to approach the problem: if you want to use custom directives as shared variables, first you have to have the TemplateDirectiveModel implementations that you can put into the shared variable set (or into the data-model). And then, if for whatever reasons you also want them to be #import-able, or part of an already existing *FTL* macro library, you have to and insert the said TemplateDirectiveModel implementations into the FTL file using #assign and ?new. >> I say, use globals for now... Which can be even more irritating when >> you have directives that can be nested into the same kind of directive >> (like: <@ul bullet="box.gif">...<@ul bullet="arrow.gif">...</@ul>...</@ul>) > > I know. Or see if Jonathan's tip on using > env.getCurrentNameSpace().get() will help in cases like this. Not regarding the lastly mentioned issue... there you have to implement some kind of stack. (Of course that stack can be the global or namespace variable.) > Ahh - meanwhile, I'll just have to be content with what can get done > now. > > - Alistair A. Israel -- Best regards, Daniel Dekany ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/