Discussion:
[FreeMarker-user] templating with no file based system (OSGI question)
halil
2015-05-20 14:15:16 UTC
Permalink
Hi All,

I am developing a web application based on OSGI. I have templates on
different bundles and want to produce a html code by merging differnt ftl
files which are on different bundles. I need this scenario because I need
versioned templates...

I am expecting to find JAVA API Documentation but could not find. I want to
implement programmatically which is done as below with Freemarker template
language.

<#macro myLayout>
<html>
<body style="width:100%;height:100%">
<table border="1" cellspacing="0" cellpadding="0" style=
"width:100%;height:100%">
<tr>
<td colspan="2">
<#include "header.ftl"/>
</td>
</tr>
<tr>
<td>
<#include "menu.ftl"/>
</td>
<td>
<#nested/>
</td>
</tr>
<tr>
<td colspan="2">
<#include "footer.ftl"/>
</td>
</tr>
</table>
</body>
</html>
</#macro>


I need such hypothetical java api which does above templating.

Freemarker.macro("mylayout.ftl")
.include(1,"header.ftl")
.include(2,"menu.ftl")
.include(3,"footer.ftl")
.process(FileUtils.read("nested.ftl"));


I see that Freemarker include directive refers to the files, meanly it is
file system based. I could not find a documentation which helps me do it
programmatically as above...

I am on a wrong way? or I missed something in the understanding of
Freemarker architecture? I don't know...

Could you please help me on this issue?

thanks in advance,


-halil.
Daniel Dekany
2015-05-20 22:48:13 UTC
Permalink
FreeMarker template loading is not file system based. See
Configuration.setTemplateLoader(...), or the convenience methods like
setClassLoaderForTemplateLoading. So as far as OSGi allows the
FreeMarker classes to access the classes of the other bundle (which
contains the templates), a ClassTemplateLoader should do the trick.
Post by halil
Hi All,
I am developing a web application based on OSGI. I have templates
on different bundles and want to produce a html code by merging
differnt ftl files which are on different bundles. I need this
scenario because I need versioned templates...
I am expecting to find JAVA API Documentation but could not find. I
want to implement programmatically which is done as below with Freemarker template language.
<#macro myLayout>
<html>
<body style="width:100%;height:100%">
<table border="1" cellspacing="0" cellpadding="0" style="width:100%;height:100%">
<tr>
<td colspan="2">
<#include "header.ftl"/>
</td>
</tr>
<tr>
<td>
<#include "menu.ftl"/>
</td>
<td>
<#nested/>
</td>
</tr>
<tr>
<td colspan="2">
<#include "footer.ftl"/>
</td>
</tr>
</table>
</body>
</html>
</#macro>
I need such hypothetical java api which does above templating.
Freemarker.macro("mylayout.ftl")
.include(1,"header.ftl")
.include(2,"menu.ftl")
.include(3,"footer.ftl")
.process(FileUtils.read("nested.ftl"));
I see that Freemarker include directive refers to the files, meanly
it is file system based. I could not find a documentation which
helps me do it programmatically as above...
I am on a wrong way? or I missed something in the understanding of
Freemarker architecture? I don't know...
Could you please help me on this issue?
thanks in advance,
-halil.
--
Thanks,
Daniel Dekany
Loading...