xdhmoore xdhmoore - 1 year ago 155
HTML Question

Multi-language auto-escape in Freemarker

I recently turned on auto-escaping in Freemarker and change my

files to
to make sure they get formatted/escaped as HTML. However, this means that any inline
tags get HTML escaped, which is not what I want. I can solve the problem by doing this:

[#outputformat "JavaScript"]

This works, but it seems like a lot of work to add this wrapper around the contents of every script tag. It seems it would make sense to have a OutputFormat that is smart enough to detect script/style tags and use the right format, or alternatively custom tags that have the same effect as the above. Something like:


Does anything like this (or anything else that solves this problem) already exist? I haven't been able to find anything.

Answer Source

Other than pre-processing templates in a custom TemplateLoader (which wraps another TemplateLoader and filters the Reader returned by it), there's no solution for this currently. Macros won't help either, because #outputformat doesn't have runtime effect. It just associates sections of the FTL source code with an output format.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download