extend the Include or Environment classes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

extend the Include or Environment classes

Francis Mendoza
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". 

   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 StreetBRISBANE, QLD 4000.

Phone:  04231 53500

email:  [hidden email]



------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: extend the Include or Environment classes

Denis Bredelet
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 StreetBRISBANE, QLD 4000.

Phone:  04231 53500

email:  [hidden email]


------------------------------------------------------------------------------
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
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: extend the Include or Environment classes

Attila Szegedi-3
In reply to this post by Francis Mendoza
You should configure your Configuration object with a MultiTemplateLoader that composes two template loaders: one for usual directory, and another one for the common directory.

Attila.

On Jun 27, 2011, at 4:58 PM, Francis Mendoza wrote:

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". 

   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? 
   
--

JET Team
Flight Centre Technology
Level 4, 545 Queen StreetBRISBANE, QLD 4000.
Phone:  04231 53500
email:  [hidden email]

------------------------------------------------------------------------------
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
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: extend the Include or Environment classes

Francis Mendoza
In reply to this post by Denis Bredelet
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? 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 <[hidden email]> 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 StreetBRISBANE, QLD 4000.

Phone:  04231 53500

email:  [hidden email]


------------------------------------------------------------------------------
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
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel




--

Francis Mendoza


JET Team

Flight Centre Technology

Level 4, 545 Queen StreetBRISBANE, QLD 4000.

Phone:  04231 53500

email:  [hidden email]



------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: extend the Include or Environment classes

Denis Bredelet
Hello

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? This may seem like a stupid question but im a little dizzy. I know im almost there....

I think you could get it working, but Attila's advice seems better. Create a template loader that combines two template loaders. Attila is one of FreeMarker devs...

-- Denis. 





On Tue, Jun 28, 2011 at 3:55 PM, Denis Bredelet <[hidden email]> 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 StreetBRISBANE, QLD 4000.

Phone:  04231 53500

email:  [hidden email]



------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: extend the Include or Environment classes

Daniel Dekany
In reply to this post by Francis Mendoza
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 <[hidden email]> 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:  [hidden email]
>
> ------------------------------------------------------------------------------
> 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
> [hidden email]
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/freemarker-devel
>
>
>
>

--
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
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: extend the Include or Environment classes

Francis Mendoza
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. 
  
   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? 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. 



   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 <[hidden email]> 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 <[hidden email]> 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:  [hidden email]
>
> ------------------------------------------------------------------------------
> 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
> [hidden email]
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/freemarker-devel
>
>
>
>

--
Best regards,
 Daniel Dekany




--

Francis Mendoza


JET Team

Flight Centre Technology

Level 4, 545 Queen StreetBRISBANE, QLD 4000.

Phone:  04231 53500

email:  [hidden email]



------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: extend the Include or Environment classes

Denis Bredelet
Hello Francis

I am not clear what issue you are having with the MultiTemplateLoader. It should try the first loader, and fall back to the second for each #include

   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? I'm a little lost on the API.

Yes you should write your own code for execute. I think the example in the directive doc is quite clear. 

-- Denis. 


   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. 



   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 <[hidden email][hidden email]> 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 <[hidden email][hidden email]> 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:  [hidden email][hidden email]
>
> ------------------------------------------------------------------------------
> 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
> [hidden email][hidden email]
> 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
> [hidden email][hidden email]
> https://lists.sourceforge.net/lists/listinfo/freemarker-devel
>
>
>
>

--
Best regards,
 Daniel Dekany




--

Francis Mendoza


JET Team

Flight Centre Technology

Level 4, 545 Queen StreetBRISBANE, QLD 4000.

Phone:  04231 53500

email:  [hidden email]


------------------------------------------------------------------------------
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
[hidden email]
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: extend the Include or Environment classes

Daniel Dekany
In reply to this post by Francis Mendoza
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 <[hidden email]> 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 <[hidden email]> 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:  [hidden email]
>>
>> ------------------------------------------------------------------------------
>> 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
>> [hidden email]
>> 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
>> [hidden email]
>> 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
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Include acquisition

Denis Bredelet

Daniel Dekany wrote:


I didn't know about this feature. It is cool, but how do you make sure templates are not loaded from a wrong place?

Eg. <#include "*/tmp/quickfix.ftl">

Is there a configuration setting that tells Freemarker /tmp is off-limits? A way to tell the minimum length or minimum prefix of the wildcard part. 

Cheers
-- Denis. 

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Include acquisition

Daniel Dekany
Wednesday, June 29, 2011, 1:13:28 PM, Denis Bredelet wrote:

>
> Daniel Dekany wrote:
>
>
> You also know this feature?
> http://freemarker.org/docs/ref_directive_include.html#ref_directive_include_acquisition
>
> I didn't know about this feature. It is cool, but how do you make
> sure templates are not loaded from a wrong place?

What exactly do you mean? The "*" is only replaced with the current
directory, and then by its parent directories, until the template is
found. So it's not like it searches the template everywhere.

> Eg. <#include "*/tmp/quickfix.ftl">
>
> Is there a configuration setting that tells Freemarker /tmp is
> off-limits?

No, but you have included "tmp" in the path above, so then why would
you want to exclude "tmp"?

> A way to tell the minimum length or minimum prefix of the wildcard part.

Nope.

(FM acquisition do have a problems though... If template A includes
template */B, and then template B includes */C, the searching of C
starts from the (real) directory of B, not from the directory of A.
Some may thinks that's all right, but it's just not how acquisition
meant to work.)

> Cheers
> -- Denis.

--
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
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Include acquisition

Denis Bredelet

Daniel Dekany wrote:

> Wednesday, June 29, 2011, 1:13:28 PM, Denis Bredelet wrote:
>
>>
>> Daniel Dekany wrote:
>>
>>
>> You also know this feature?
>> http://freemarker.org/docs/ref_directive_include.html#ref_directive_include_acquisition
>>
>> I didn't know about this feature. It is cool, but how do you make
>> sure templates are not loaded from a wrong place?
>
> What exactly do you mean? The "*" is only replaced with the current
> directory, and then by its parent directories, until the template is
> found. So it's not like it searches the template everywhere.

What I mean is that I have things that have nothing to do with Freemarker at the root of the drive. If a template is missing, I am afraid this feature could load malicious content inadvertently.

>
>> Eg. <#include "*/tmp/quickfix.ftl">
>>
>> Is there a configuration setting that tells Freemarker /tmp is
>> off-limits?
>
> No, but you have included "tmp" in the path above, so then why would
> you want to exclude "tmp"?

I want to exclude /tmp because that directory is typically world-writable.

-- Denis.

>
>> A way to tell the minimum length or minimum prefix of the wildcard part.
>
> Nope.
>
> (FM acquisition do have a problems though... If template A includes
> template */B, and then template B includes */C, the searching of C
> starts from the (real) directory of B, not from the directory of A.
> Some may thinks that's all right, but it's just not how acquisition
> meant to work.)
>
>> Cheers
>> -- Denis.
>
> --
> 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
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Include acquisition

Daniel Dekany
Wednesday, June 29, 2011, 11:55:24 PM, Denis Bredelet wrote:

>
> Daniel Dekany wrote:
>
>> Wednesday, June 29, 2011, 1:13:28 PM, Denis Bredelet wrote:
>>
>>>
>>> Daniel Dekany wrote:
>>>
>>>
>>> You also know this feature?
>>> http://freemarker.org/docs/ref_directive_include.html#ref_directive_include_acquisition
>>>
>>> I didn't know about this feature. It is cool, but how do you make
>>> sure templates are not loaded from a wrong place?
>>
>> What exactly do you mean? The "*" is only replaced with the current
>> directory, and then by its parent directories, until the template is
>> found. So it's not like it searches the template everywhere.
>
> What I mean is that I have things that have nothing to do with
> Freemarker at the root of the drive. If a template is missing, I am
> afraid this feature could load malicious content inadvertently.

FreeMarker templates doesn't work with real paths; they are stuck
inside the virtual file-system implemented by the TemplateLoader. Like
if you setup FreeMarker with
cfg.setDirectoryForTemplateLoading("/foo/bar/templates"), then when a
template says "/" it's translated to "/foo/bar/templates" by the
TemplateLoader. If the template says "/../../../etc/passwd", that's an
error as you can't leave the virtual root. It's like chroot cage. Of
course, acquisition also has to stop at the virtual root.

>>> Eg. <#include "*/tmp/quickfix.ftl">
>>>
>>> Is there a configuration setting that tells Freemarker /tmp is
>>> off-limits?
>>
>> No, but you have included "tmp" in the path above, so then why would
>> you want to exclude "tmp"?
>
> I want to exclude /tmp because that directory is typically world-writable.

So, because of what I said above, there's no such danger. Or if there
is, then that was there regardless of acquisition.

> -- Denis.
>
>>
>>> A way to tell the minimum length or minimum prefix of the wildcard part.
>>
>> Nope.
>>
>> (FM acquisition do have a problems though... If template A includes
>> template */B, and then template B includes */C, the searching of C
>> starts from the (real) directory of B, not from the directory of A.
>> Some may thinks that's all right, but it's just not how acquisition
>> meant to work.)
>>
>>> Cheers
>>> -- Denis.
>>
>> --
>> 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
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
Reply | Threaded
Open this post in threaded view
|

Re: Include acquisition

Denis Bredelet
Great! Thanks for the info. I should look more into template loading.

-- Denis.

On 29 Jun 2011, at 23:45, Daniel Dekany <[hidden email]> wrote:

> Wednesday, June 29, 2011, 11:55:24 PM, Denis Bredelet wrote:
>
>>
>> Daniel Dekany wrote:
>>
>>> Wednesday, June 29, 2011, 1:13:28 PM, Denis Bredelet wrote:
>>>
>>>>
>>>> Daniel Dekany wrote:
>>>>
>>>>
>>>> You also know this feature?
>>>> http://freemarker.org/docs/ref_directive_include.html#ref_directive_include_acquisition
>>>>
>>>> I didn't know about this feature. It is cool, but how do you make
>>>> sure templates are not loaded from a wrong place?
>>>
>>> What exactly do you mean? The "*" is only replaced with the current
>>> directory, and then by its parent directories, until the template is
>>> found. So it's not like it searches the template everywhere.
>>
>> What I mean is that I have things that have nothing to do with
>> Freemarker at the root of the drive. If a template is missing, I am
>> afraid this feature could load malicious content inadvertently.
>
> FreeMarker templates doesn't work with real paths; they are stuck
> inside the virtual file-system implemented by the TemplateLoader. Like
> if you setup FreeMarker with
> cfg.setDirectoryForTemplateLoading("/foo/bar/templates"), then when a
> template says "/" it's translated to "/foo/bar/templates" by the
> TemplateLoader. If the template says "/../../../etc/passwd", that's an
> error as you can't leave the virtual root. It's like chroot cage. Of
> course, acquisition also has to stop at the virtual root.
>
>>>> Eg. <#include "*/tmp/quickfix.ftl">
>>>>
>>>> Is there a configuration setting that tells Freemarker /tmp is
>>>> off-limits?
>>>
>>> No, but you have included "tmp" in the path above, so then why would
>>> you want to exclude "tmp"?
>>
>> I want to exclude /tmp because that directory is typically world-writable.
>
> So, because of what I said above, there's no such danger. Or if there
> is, then that was there regardless of acquisition.
>
>> -- Denis.
>>
>>>
>>>> A way to tell the minimum length or minimum prefix of the wildcard part.
>>>
>>> Nope.
>>>
>>> (FM acquisition do have a problems though... If template A includes
>>> template */B, and then template B includes */C, the searching of C
>>> starts from the (real) directory of B, not from the directory of A.
>>> Some may thinks that's all right, but it's just not how acquisition
>>> meant to work.)
>>>
>>>> Cheers
>>>> -- Denis.
>>>
>>> --
>>> 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
> _______________________________________________
> FreeMarker-devel mailing list
> [hidden email]
> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel