Re: Omitting template markup characters
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Wednesday, April 28, 2010, 11:01:06 AM, Kjeld wrote:
>
> I used some whitespaces / indentation in my template file to make it more
> readable like so:
>
> <#list my collection as item>
> ${"11"}
> ${item.id?string?left_pad(12, "0")}
> ${item.labelCode?right_pad(10)}
> ${"\r\n"}
> </#list>
>
> Which produces something like:
>
> 11
> 000000000123
> aCode
>
> ...because of the whitespaces and line breaks in my template file. Bubut
> what I actually want it to produce is:
>
> 11000000000123aCode
Note that you can also use your own TemplateDirectiveModel for this,
like
<@my.pack>
<#list ...>
...
</#list>
</@my.pack>
however that will act on the output of the template, which means
runtime overhead. But sometimes it's more appropriate...
> I solved this by preprocessing the template file to a temp file, omitting
> whitespaces etc and using that temp file. Considering time and performance
> for now this is adequate for me.
> Still, I briefly looked into the custom TemplateLoader option and I did not
> find an appropriate example. I created a MyTemplateLoader implements
> TemplateLoader (also tried extending FileTemplateLoader) and fed it to
> configuration. But when I use
> configuration.setDirectoryForTemplateLoading
> afterwards, configuration.getTemplateLoader returns its default
> FileTemplateLoader again...:S Why is that?
> More importantly, I noticed MyTemplateLoader.getReader is never accessed.
> Any ideas?
cfg.setDirectoryForTemplateLoading is just a convenient shorthand for
cfg.setTemplateLoader(new FileTemplateLoader(theDir)), so it replaces
your template loader.
> Cheers
> Kjeld
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------