Include a Freemarker template from repo in another Freemarker template

80 views
Skip to first unread message

Arje Cahn

unread,
Feb 4, 2014, 6:04:03 AM2/4/14
to hippo-c...@googlegroups.com
Hi guys,

Quick question.
I have my Freemarker templates stored in the repository. I want to add another Freemarker template in my repo with a bunch of reusable <#macro>s, and include that file from my other templates.

This works for templates on the filesystem:
<#include "/WEB-INF/lib/htmlTags.ftl">

Do we have an equivalent for including templates in the repo?

Arje

Ard Schrijvers

unread,
Feb 4, 2014, 6:35:14 AM2/4/14
to hippo-c...@googlegroups.com
I am not sure if I got it working in the past, but I think you could try

<#include "repository://absolute/repo/path/to/htmlTags.ftl">

Let me know it that helps. I can't even completely recall if I got it
working in the past or whether it was still a todo

Regards Ard

>
> Arje
>
> --
> Hippo Community Group: The place for all discussions and announcements about
> Hippo CMS (and HST, repository etc. etc.)
> Most Hippo developers are active here and/or follow the Stackoverflow
> [hippo-cms] tag.
>
> To post to this group, send email to hippo-c...@googlegroups.com
> RSS:
> https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
> ---
> You received this message because you are subscribed to the Google Groups
> "Hippo Community" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to hippo-communi...@googlegroups.com.
> Visit this group at http://groups.google.com/group/hippo-community.
> For more options, visit https://groups.google.com/groups/opt_out.



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

Joeri de Gooijer

unread,
Feb 4, 2014, 7:13:14 AM2/4/14
to hippo-c...@googlegroups.com
Well I tried it like this in the layout.webpage.ftl template.
I changed the include from:
<#include "/WEB-INF/lib/htmlTags.ftl">
to
<#include "repository://hst:hst/hst:configurations/commononehippo/hst:templates/htmlTags.ftl">

That didnt work however.

The log shows:
[INFO] [talledLocalContainer] 04.02.2014 13:01:54 ERROR [freemarker.log.Log4JLoggerFactory$Log4JLogger.error():96] Template processing error: "Expression hst is undefined on line 98, column 7 in jcr:/hst:hst/hst:configurations/commononehippo/hst:templates/layout.webpage.ftl."

So appearantly the hst variable in the htmlTags.ftl is not available in the layout.webpage.ftl template now.

htmlTags.ftl:
<#ftl encoding="UTF-8">
<#assign hst=JspTaglibs["http://www.hippoecm.org/jsp/hst/core"] >
<#assign fmt=JspTaglibs ["http://java.sun.com/jsp/jstl/fmt"] >
<#assign zohotags=JspTaglibs["http://onehippo.com/jsp/connect/zoho/tags"] >

...
...more stuff here
...

<@hst.defineObjects />

Ard Schrijvers

unread,
Feb 4, 2014, 9:22:55 AM2/4/14
to hippo-c...@googlegroups.com
On Tue, Feb 4, 2014 at 1:13 PM, Joeri de Gooijer <j.deg...@1hippo.com> wrote:
> Well I tried it like this in the layout.webpage.ftl template.
> I changed the include from:
> <#include "/WEB-INF/lib/htmlTags.ftl">
> to
> <#include
> "repository://hst:hst/hst:configurations/commononehippo/hst:templates/htmlTags.ftl">
>
> That didnt work however.
>
> The log shows:
> [INFO] [talledLocalContainer] 04.02.2014 13:01:54 ERROR
> [freemarker.log.Log4JLoggerFactory$Log4JLogger.error():96] Template
> processing error: "Expression hst is undefined on line 98, column 7 in
> jcr:/hst:hst/hst:configurations/commononehippo/hst:templates/layout.webpage.ftl."
>
> So appearantly the hst variable in the htmlTags.ftl is not available in the
> layout.webpage.ftl template now.

I vaguely recall I tried this in the past. Does not work currently.

Regards Ard

Joeri de Gooijer

unread,
Feb 4, 2014, 9:24:24 AM2/4/14
to hippo-c...@googlegroups.com
Ok, thanks for replying Ard!

Ard Schrijvers

unread,
Feb 4, 2014, 9:25:49 AM2/4/14
to hippo-c...@googlegroups.com
On Tue, Feb 4, 2014 at 3:24 PM, Joeri de Gooijer <j.deg...@1hippo.com> wrote:
> Ok, thanks for replying Ard!

Note that I think it should be possible to fix it. I just don't really
recall any more the exact issues. Was couple of years back already. If
needed I can check it out again some day

Regards Ard

Woonsan Ko

unread,
Feb 4, 2014, 9:29:14 AM2/4/14
to hippo-c...@googlegroups.com
On 2/4/14 6:35 AM, Ard Schrijvers wrote:
> On Tue, Feb 4, 2014 at 12:04 PM, Arje Cahn <a.c...@onehippo.com> wrote:
>> Hi guys,
>>
>> Quick question.
>> I have my Freemarker templates stored in the repository. I want to add
>> another Freemarker template in my repo with a bunch of reusable <#macro>s,
>> and include that file from my other templates.
>>
>> This works for templates on the filesystem:
>> <#include "/WEB-INF/lib/htmlTags.ftl">
>>
>> Do we have an equivalent for including templates in the repo?
>
> I am not sure if I got it working in the past, but I think you could try
>
> <#include "repository://absolute/repo/path/to/htmlTags.ftl">

I haven't ever tried it, but based on [1] I guess you should have
recommended using "jcr:" instead of "repository:".
So,

<#include "jcr:/absolute/repo/path/to/htmlTags.ftl">

Might be one more try? :)

[1]
http://svn.onehippo.org/repos/hippo/hippo-cms7/site-toolkit/trunk/client/src/main/java/org/hippoecm/hst/freemarker/RepositoryTemplateLoader.java

>
> Let me know it that helps. I can't even completely recall if I got it
> working in the past or whether it was still a todo
>
> Regards Ard
>
>>
>> Arje
>>
>> --
>> Hippo Community Group: The place for all discussions and announcements about
>> Hippo CMS (and HST, repository etc. etc.)
>> Most Hippo developers are active here and/or follow the Stackoverflow
>> [hippo-cms] tag.
>>
>> To post to this group, send email to hippo-c...@googlegroups.com
>> RSS:
>> https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Hippo Community" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to hippo-communi...@googlegroups.com.
>> Visit this group at http://groups.google.com/group/hippo-community.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>


--
w....@onehippo.com www.onehippo.com
Boston - 101 Main Street, Cambridge, MA 02142
Amsterdam - Oosteinde 11, 1017 WT Amsterdam

Ard Schrijvers

unread,
Feb 4, 2014, 9:38:17 AM2/4/14
to hippo-c...@googlegroups.com
On Tue, Feb 4, 2014 at 3:29 PM, Woonsan Ko <w....@onehippo.com> wrote:
> On 2/4/14 6:35 AM, Ard Schrijvers wrote:
>> On Tue, Feb 4, 2014 at 12:04 PM, Arje Cahn <a.c...@onehippo.com> wrote:
>>> Hi guys,
>>>
>>> Quick question.
>>> I have my Freemarker templates stored in the repository. I want to add
>>> another Freemarker template in my repo with a bunch of reusable <#macro>s,
>>> and include that file from my other templates.
>>>
>>> This works for templates on the filesystem:
>>> <#include "/WEB-INF/lib/htmlTags.ftl">
>>>
>>> Do we have an equivalent for including templates in the repo?
>>
>> I am not sure if I got it working in the past, but I think you could try
>>
>> <#include "repository://absolute/repo/path/to/htmlTags.ftl">
>
> I haven't ever tried it, but based on [1] I guess you should have
> recommended using "jcr:" instead of "repository:".
> So,
>
> <#include "jcr:/absolute/repo/path/to/htmlTags.ftl">
>
> Might be one more try? :)

Ah, yeah, it should be jcr: :). Nice catch!

Certainly worth another try, although I thought the #include did not
work with the jcr: prefix. Or perhaps it does work, but invalidation
did not work. I thought something did not work :)

Regards Ard
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

Joeri de Gooijer

unread,
Feb 4, 2014, 10:18:57 AM2/4/14
to hippo-c...@googlegroups.com
Hmm gave it a shot but
<#include "jcr:/hst:hst/hst:configurations/commononehippo/hst:templates/htmlTags.ftl">

Gives me the same log error.

Arje Cahn

unread,
Feb 4, 2014, 5:25:11 PM2/4/14
to hippo-c...@googlegroups.com
Changing that to jcr:// did seem to help - looks like the template now at least gets resolved.
But I still get errors.
Putting this on my wish list.

Arje

Ard Schrijvers

unread,
Feb 5, 2014, 1:50:11 AM2/5/14
to hippo-c...@googlegroups.com


Op 4 feb. 2014 23:25 schreef "Arje Cahn" <a.c...@onehippo.com> het volgende:


>
> Changing that to jcr:// did seem to help - looks like the template now at least gets resolved.
> But I still get errors.
> Putting this on my wish list.

Ideally you could use a relative location within the repository such that you would not need the jcr:// at all. Indeed i experienced some issues with including templates it the past. Did not look into it how hard it was to solve.

Regards ard

marijan milicevic

unread,
Feb 7, 2014, 7:27:54 AM2/7/14
to hippo-c...@googlegroups.com
I just checked this,
and includes are resolved *relative* to your source file, so, for example, if you have myhome.ftl:

/hst:hst/hst:configurations/democommon/hst:templates/myhome.ftl

with following include file
<#include "myinclude.ftl">

include will be resolved to:
/hst:hst/hst:configurations/democommon/hst:templates/myinclude.ftl

cheers
marijan


Ard Schrijvers

unread,
Feb 7, 2014, 7:32:04 AM2/7/14
to hippo-c...@googlegroups.com
On Fri, Feb 7, 2014 at 1:27 PM, marijan milicevic
<m.mil...@onehippo.com> wrote:
> I just checked this,
> and includes are resolved *relative* to your source file, so, for example,
> if you have myhome.ftl:
>
> /hst:hst/hst:configurations/democommon/hst:templates/myhome.ftl
>
> with following include file
> <#include "myinclude.ftl">
>
> include will be resolved to:
> /hst:hst/hst:configurations/democommon/hst:templates/myinclude.ftl

Nice!

do you know if relative includes also work? For example ../../common/foo.ftl

Regards Ard

marijan milicevic

unread,
Feb 7, 2014, 7:41:04 AM2/7/14
to hippo-c...@googlegroups.com
On Fri, Feb 7, 2014 at 1:32 PM, Ard Schrijvers <a.schr...@onehippo.com> wrote:
On Fri, Feb 7, 2014 at 1:27 PM, marijan milicevic
<m.mil...@onehippo.com> wrote:
> I just checked this,
> and includes are resolved *relative* to your source file, so, for example,
> if you have myhome.ftl:
>
> /hst:hst/hst:configurations/democommon/hst:templates/myhome.ftl
>
> with following include file
> <#include "myinclude.ftl">
>
> include will be resolved to:
> /hst:hst/hst:configurations/democommon/hst:templates/myinclude.ftl

Nice!

do you know if relative includes also work? For example ../../common/foo.ftl


that doesn't work, but this does:
<#include "../../common/hst:templates/myinclude.ftl">

 
cheers
marijan

Ard Schrijvers

unread,
Feb 7, 2014, 8:00:34 AM2/7/14
to hippo-c...@googlegroups.com
On Fri, Feb 7, 2014 at 1:41 PM, marijan milicevic
<m.mil...@onehippo.com> wrote:
> On Fri, Feb 7, 2014 at 1:32 PM, Ard Schrijvers <a.schr...@onehippo.com>
> wrote:
>>
>> On Fri, Feb 7, 2014 at 1:27 PM, marijan milicevic
>> <m.mil...@onehippo.com> wrote:
>> > I just checked this,
>> > and includes are resolved *relative* to your source file, so, for
>> > example,
>> > if you have myhome.ftl:
>> >
>> > /hst:hst/hst:configurations/democommon/hst:templates/myhome.ftl
>> >
>> > with following include file
>> > <#include "myinclude.ftl">
>> >
>> > include will be resolved to:
>> > /hst:hst/hst:configurations/democommon/hst:templates/myinclude.ftl
>>
>> Nice!
>>
>> do you know if relative includes also work? For example
>> ../../common/foo.ftl
>>
>
> that doesn't work, but this does:
> <#include "../../common/hst:templates/myinclude.ftl">

My point was whether ../ also works, but you just confirmed it does, great!

Arje Cahn

unread,
Feb 8, 2014, 3:05:12 AM2/8/14
to hippo-c...@googlegroups.com, hippo-c...@googlegroups.com
Excellent! Thanks, Marijan.

Btw - I thought it would be nice to collect useful Freemarker snippets in our documentation so I added this page: http://www.onehippo.org/7_8/library/concepts/web-application/freemarker-snippets.html
Feel free to join the effort :)

Arje

Sent from my iphone.
Apologies for my terseness and typos.
Reply all
Reply to author
Forward
0 new messages