Re: Shared variables vs. auto-imported templates (freemarker-tags plugin)
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Wednesday, July 13, 2011, 4:53:02 AM, Daniel Henrique Alves Lima wrote:
> I've updated some links.
> ====
>
> Hi, everybody.
>
> Daniel, I'm pretty sure we've talked about this before, but I can't
> remember where (I read
> http://freemarker.624813.n4.nabble.com/Configuration-setup-td3315086.html
> and
> http://freemarker.624813.n4.nabble.com/Grails-integration-td3161875.html).
> Can you help me?
>
> I'm rewriting freemarker-tags and exposing the directives and
> functions as values in shared maps
> (https://github.com/daniel-lima/grails-freemarker-tags-plugin/blob/master/src/java/org/grails/plugins/freemarker/AbstractTagLibAwareConfigurer.java#L154).
>
> Suppose that my tests will be the base of our discussion:
> https://github.com/daniel-lima/grails-freemarker-tags-plugin/blob/master/test/integration/org/grails/plugins/freemarker/TagLibAwareConfigurerTests.groovy#L46
>
> http://pastie.org/2203040
>
>
> Now, my doubt: If my data model ('binding' in my test case -
> https://github.com/daniel-lima/grails-freemarker-tags-plugin/blob/master/test/integration/org/grails/plugins/freemarker/TagLibAwareConfigurerTests.groovy#L81)
> contains a variable named as 'g', it will shadowing '[@g.form /]', right?
Yes, data-model shadows shared variables.
> /* template, data model */
> parseFtlTemplate('[#ftl/][@g.form /]', [g: 'random text'])
>
> Will the shadowing also happen if I do the auto-importing of
> libraries containing macro or function declarations (instead of using
> shared variables)?
No, since the variables assigned during the processing of the
templates shadow the data-model and the shared variables.
See also: http://freemarker.org/docs/pgui_misc_var.html
> Something like:
>
> [!-- g.ftl --]
> [#assign form = "TagLibToDirectiveAndFunction"?new('g', 'form')]
>
> // AbstractTagLibAwareConfigurer.java
> configuration.addAutoImport('g', 'g.ftl')
>
> /* template, data model */
> parseFtlTemplate('[#ftl/][@g.form /]', [g: 'random text'])
>
>
> Is my question clear? I can try to rewrite it, if you prefer.
>
> Thanks in advance.
>
> Best regards,
>
> Daniel.
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric
Ries, the creator of the Lean Startup Methodology on "Lean Startup
Secrets Revealed." This video shows you how to validate your ideas,
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev