Re: Best way to pass parameter to custom TemplateLoader?

Chris <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
You guys are brilliant.

The problem with the template cache hadn't occurred to me, and it would 
not have shown up in development for a while.

The scheme in which I encode arbitrary information before the :// worked 
perfectly, even with multiple nested [#includes].

This solution is simple, clean, slick, and has no possibility of causing 
threading problems. It's also generalizable for future template loaders.


On 7/12/2011 2:45 AM, Daniel Dekany wrote:
> You should encode the relevant information from the HttpServletRequest
> into the template name. For example, you could have template names
> like "tree1://foo/bar.ftl" and "tree2://foo/bar.ftl" and so on. Then
> your TemplateLoader should delegate to other TemplateLoader-s based on
> the part before the "://" (which can be anything BTW, like even
> "user=joe,application=accounting://"). If you wonder why
> "tree1://foo/bar.ftl" is better than "tree1/foo/bar.ftl", it's because
> absolute paths in bar.ftl, like in<#import "/baaz.ftl" as b>, will be
> resolved to "tree1://baaz.ftl" in the first case, but to "baaz.ftl",
> which is not correct. (You could still do cross-tree inclusions
> explicitly, like with "tree2://something.ftl".)
>



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