Re: Shared variables vs. auto-imported templates (freemarker-tags plugin)
Daniel Henrique Alves Lima <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Hi, Daniel. Thanks for your answers.
Sometimes I just feel stupid asking this kind of question, but I've
been working with a lot of different stuff and I'm not a fast learner
anymore :-/
Daniel, after reading the docs I suppose that something like this
won't work, right?
[!-- g.ftl --]
[#assign form = .globals[form]]
// AbstractTagLibAwareConfigurer.java
configuration.addAutoImport('g', 'g.ftl')
/* template, data model */
parseFtlTemplate('[#ftl/][@g.form /]', [g: 'random text'])
Because the data model will also be global: "(...) In practice, from the viewpoint of template authors these 6 layers are only 4 layers, since from that viewpoint the last 3 layers (variables created with global, the actual data-model object, shared variables) together constitute the set of global variables. (...)"
I'm trying to avoid the unnecessary object creation here.
Why can't I access the Environment from a TemplateMethodModelEx? If
globals don't solve my problem, I could write a TemplateMethodModelEx to
return variables using Configuration.getSharedVariable():
[!-- g.ftl --]
[#assign form = weirdSharedVariableNameToGetSharedVariables('g', 'form')]
// AbstractTagLibAwareConfigurer.java
configuration.addAutoImport('g', 'g.ftl')
/* template, data model */
parseFtlTemplate('[#ftl/][@g.form /]', [g: 'random text'])
Thanks in advance.
Best regards,
Daniel.
Daniel Dekany wrote:
> Wednesday, July 13, 2011, 4:53:02 AM, Daniel Henrique Alves Lima wrote:
>
> (...)
> 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.
>>
>
>
------------------------------------------------------------------------------
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