Re: extend the Include or Environment classes

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.devel
Message-ID <[email protected]>
Wednesday, June 29, 2011, 8:49:57 AM, Francis Mendoza wrote:

> Hi All,
>
>     My bad, the @test is closed with @test. sorry for that typo. I
> tried Attila's suggestion but it doesn't fit my requirement. I can
> get it to resolve to the MultiTemplateLoaders I define but each
> template I use has a bunch of includes in it that must each resolve
> (if it fails). The directive seems to be the right solution for me. 

You also know this feature?
http://freemarker.org/docs/ref_directive_include.html#ref_directive_include_acquisition

>    Daniel, can you give like a snippet on how to access this 
> @myFramework.include "test2.ftl"  inside
> the implemented TemplateDirectiveModel class?  Im suppose to
> implement my own stuff inside the execute method right?

Yes. freemarker.core.Environment has "getTemplate",
"getTemplateForInclusing", even "include" methods.

> I'm a little lost on the API.
>
>    Again, thanks for replying everyone. I really appreciate it.
> There's not much detailed examples in the net on Freemarker. Its
> such a shame because its really a cool templating engine. I'll
> probably make one if I can get this to work. 

The Manual contains an example of a Directive AFAIR. Others should be
extracted from the JavaDoc-s, which may require improvement however...

>
>
>    I'll try this @myFramework.include "test2.ftl" by Daniel in a while. Just need
>
> On Wed, Jun 29, 2011 at 5:30 AM, Daniel Dekany <[email protected]> wrote:
> Tuesday, June 28, 2011, 2:30:12 PM, Francis Mendoza wrote:
>
>> Hi Denis,
>>
>>    Thanks for your quick reply. I've had a time to play around with
>> the directive at the moment and I seem to get your point. I'm just
>> testing stuff out of the example Freemarker gave as per your given link.
>>
>>   Im almost there but I have a question, how can I achieve this:
>>
>> <@test y="test2.ftl">
>>
>>   <#include y>
>> </@repeat>
>>
>> and my class "Test" implements TemplateDirectiveModel? How can I
>> get the y to be rendered inside the @test?
>
> I suspects there are some misunderstanding regarding how directives
> supposed to work. Why @test is closed with @repeat? Why would y be
> visible for the #include when it was just a parameter to @test?
> Anyway, if you just wanted something like #include but with a somewhat
> different behavior, certainly you should just implement a directive
> that does that directly. Something like:
>
>  <@myFramework.include "test2.ftl" />
>
> and then in the implementation of "include" you can use the
> Environment API to try to include templates, etc.
>
> Or, as Attila said, maybe a MultiTemplateLoader is the good solution.
>
>
>> This may seem like a
>> stupid question but im a little dizzy. I know im almost there....
>>
>>
>>
>>
>> On Tue, Jun 28, 2011 at 3:55 PM, Denis Bredelet <[email protected]> wrote:
>> Hi Francis
>>
>>
>> Hi All,
>>
>>    I'm working right now on shifting our templating engine from
>> StringTemplate to Freemarker. One of the requirement
>> was that if the .ftl file (an #include) cannot be found, it will
>> look for it at the common directory. I've look at the API and
>> Freemarker codes but there seem to be no way for me to do this on the "includes".
>>
>> If the built-in #include does not work for you, you should be able
>> to implement it with your own directive:
>>
>> http://freemarker.org/docs/pgui_datamodel_directive.html
>>
>> -- Denis.
>>
>>
>>    I checked on the Environment.java and saw the rendering of the
>> includes down there: getTemplateForInclusion. Its
>> a public method alright but then the class is marked final so I
>> can't extend it to solve my problem. Is there a possibility
>> for this class to be marked as not final on the future releases?
>>
>> --
>> Francis Mendoza
>>
>>
>> JET Team
>> Flight Centre Technology
>> Level 4, 545 Queen Street, BRISBANE, QLD 4000.
>> Phone:  04231 53500
>> email:  [email protected]
>>
>> ------------------------------------------------------------------------------
>> All of the data generated in your IT infrastructure is seriously valuable.
>> Why? It contains a definitive record of application performance, security
>> threats, fraudulent activity, and more. Splunk takes this data and makes
>> sense of it. IT sense. And common sense.
>> http://p.sf.net/sfu/splunk-d2d-c2
>> _______________________________________________
>> FreeMarker-devel mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/freemarker-devel
>>
>> ------------------------------------------------------------------------------
>> All of the data generated in your IT infrastructure is seriously valuable.
>> Why? It contains a definitive record of application performance, security
>> threats, fraudulent activity, and more. Splunk takes this data and makes
>> sense of it. IT sense. And common sense.
>> http://p.sf.net/sfu/splunk-d2d-c2
>> _______________________________________________
>> FreeMarker-devel mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/freemarker-devel
>>
> --
> Best regards,
>  Daniel Dekany

-- 
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.