Re: Omitting template markup characters

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Wednesday, April 28, 2010, 1:09:59 PM, Kjeld wrote:

>
> Wow, meanwhile I looked into the custom TemplateLoader solution again and I
> got it working now. 
> I have created a MyTemplateLoader class which extends FileTemplateLoader.
> MyTemplateLoader has one constructor which takes the custom baseDir I'd like
> to set, it propogates that baseDir to the constructor of FileTemplateLoader.

It's certainly better just encapsulating whatever TemplateLoader you
got from where you got it still now (like maybe from
cfg.getTempalteLoader), and blindly forward the method calls to it in
MyTemplateLoader, except that you fiddle with the Reader of course.
That way you don't assume that the encapsulated one is
FileTemplateLoader, only that it's a TemplateLoader. It's cleaner and
more flexible then. Like if you later decide to load templates from
other sources than the file system, it will still work.

> Next I override getReader, which calls super.getReader(...). I use this
> reader to walk through the original template file, trim the whitespaces etc
> and then I have getReader output the new content by using a new
> StringReader(content).

(That's not the fastest way due to the buffering, but in most apps it
doesn't mater.)

> This is at least far more elegant than the temp file solution.
>
> Thanks for your help Daniel!

-- 
Best regards,
 Daniel Dekany


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