Re: Nested Java directives - best practice on how to make values available to inner directive?
"Alistair Israel" <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
On Jan 31, 2008 6:09 PM, Jonathan Revusky <[email protected]> wrote: > Yes, well, the problem is that, within the nested body associated with a > macro, you are not actually within the macro -- at least from a variable > namespace resolution POV. Looking through the code again, that makes sense now. > Well, I don't think you need this to be a global variable, i.e. visible > from all namespaces. Probably, you could use: > > env.getCurrentNamespace().put("name", name); That actually worked pretty well. Thanks. Next thing I tried to do was rewrite my 'top level' @form macro as a regular FTL macro. In that macro, I assigned "formName": In "forms.ftl": <#macro form name action method="POST"> <#assign formName = name/> <#nested/> </#macro> In TextInputDirective, calling env.getLocalVariable("formName") returned null. I was able to get the value by simply using env.getVariable(), so I guess that's another 'workaround'. But when I tried to include "forms.ftl" as f, and started using <@f.form ...><@textInput ...></@form>, TextInputDirective suddenly couldn't see "formName" again - whether using getLocalVariable(), getCurrentNameSpace().get() or just getVariable(). At this point, I think I'll settle with either one of the two workarounds that actually worked - at least until 2.4 comes out, maybe. - Alistair A. Israel ------------------------------------------------------------------------- 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/