Re: Pass In a Template as String into Configuration object
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Thursday, May 14, 2009, 10:48:36 PM, Scott Purcell wrote: > > I have some templates in a DB, and would like to use them with > Freemarker. How can I take a "String" template and tell the > configurtion to use the passed in String? > > Has to be a way I would think. The templates are not files, they > will come from a DB and will be of type string. There are two approaches: - FreeMarker does NOT assume that the templates are real files. Write a custom freemarker.cache.TemplateLoader, (http://freemarker.org/docs/api/freemarker/cache/TemplateLoader.html) and plug it into the Configuration as the "template loader" setting, and that's it. - You can create Template objects from whatever string-like value by using the Template(java.lang.String name, java.io.Reader reader, Configuration cfg) constructor. However, note that in this case solving template caching is up to you. Also note that dependencies will be loaded through the "cfg", using the "name" to deduce the base path. - A solution that is kind of between the above two: Use freemarker.cache.StringTemplateLoader. (http://freemarker.org/docs/api/freemarker/cache/StringTemplateLoader.html) > Thanks, > > > CONFIDENTIALITY NOTICE > This e-mail message and any attachments are only for the use of the > intended recipient and may contain information that is privileged, > confidential or exempt from disclosure under applicable law. If you > are not the intended recipient, any disclosure, distribution or > other use of this e-mail message or attachments is prohibited. If > you have received this e-mail message in error, please delete and > notify the sender immediately. Thank you. -- Best regards, Daniel Dekany ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects