freemarker namespacing using #import breaks the site.

124 views
Skip to first unread message

Martijn van der Vorst

unread,
Nov 13, 2015, 6:01:41 AM11/13/15
to Hippo Community
Hello,

I recently started working on a site using freemarker in webfiles.
To approximate the functionality of .tag in freemarker I created some macros like:

file compoundMacros.ftl
<#macro linkCompound item ... ... >
<#-- do something here for linkCompound -->
</#macro>

when including that as:
<#include "macros/compoundMacros.ftl">
and using it as:
<@linkCompound item=document.linkCompound .. ../>
everything works as intended.

However as soon as I try to import it as:
<#import "macros/compoundMacros.ftl" as cp>
and using it as:
<@cp.linkCompound item=document.linkCompound .. ../>

the entire site breaks.

I am slightly at a loss as to why this would occur. According to the freemarker documentation of namespacing macros this should work.

Kind regards,
Martijn van der Vorst


Woonsan Ko

unread,
Nov 13, 2015, 6:17:03 AM11/13/15
to hippo-c...@googlegroups.com
Hi Martijn,

I have used #import in ftl templates in non-webfiles like the following example before and it should work.

<#import "/WEB-INF/ftl/macros/compoundMacros.ftl" as cp>
<@cp.linkCompound ... />

It might be a webfiles-env specific issue. Could you try to find full stack error logs to see where it fails exactly?

Regards,

Woonsan


--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
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/d/optout.



--
w....@onehippo.com     www.onehippo.com
Boston - 745 Atlantic Ave, 8th Floor, Boston MA 02111
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466

Martijn van der Vorst

unread,
Nov 13, 2015, 6:22:18 AM11/13/15
to Hippo Community
Hi Woonsan,

The log is filled with "unable to find item (such as document).

[INFO] [talledLocalContainer] FTL stack trace ("~" means nesting-related):
[INFO] [talledLocalContainer] - Failed at: ${document.title?html}  [in template "webfile:/freemarker/catalog/banner.ftl" at line 12, column 69]
[INFO] [talledLocalContainer] ----. To see the stack trace, set 'org.hippoecm.hst.servlet.HstFreemarkerServlet' log-level to debug in log4j configuration or runtime via the logging servlet
[WARNING] [talledLocalContainer] 11:50:57 WARN  [HstFreemarkerServlet] The following has evaluated to null or missing:
[INFO] [talledLocalContainer] ==> document  [in template "webfile:/freemarker/catalog/banner.ftl" at line 13, column 18]

Interesting though, it can no longer find ANY of the variables usually set by the Java components, this includes freemarker templates which don't use the <@cp.linkCompound/> at all.

It does seem to be something that's only problematic with the webfiles.

For now we can work around it using the method I described (no namespacing), but having properly namespaced macros would make it a lot cleaner and readable.

Kind regards,

Martijn van der Vorst

Woonsan Ko

unread,
Nov 13, 2015, 6:32:48 AM11/13/15
to hippo-c...@googlegroups.com
It would be helpful if you set the log level of org.hippoecm.hst.servlet.HstFreemarkerServlet to DEBUG.
Then, we might be able to see the full stack trace, which should be helpful to our product maintenance.

Thanks,

Woonsan

Martijn van der Vorst

unread,
Nov 13, 2015, 7:11:26 AM11/13/15
to Hippo Community
Hello Woonsan, 
I have set the log level to debug, and now the following stacktrace shows up:
 
[WARNING] [talledLocalContainer] 13:04:45 WARN  [HstFreemarkerServlet] Error in Freemarker template:
[INFO] [talledLocalContainer] FreeMarker template error:
[INFO] [talledLocalContainer] The following has evaluated to null or missing:
[INFO] [talledLocalContainer] ==> document  [in template "webfile:/freemarker/catalog/banner.ftl" at line 26, column 22]
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] ----
[INFO] [talledLocalContainer] Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
[INFO] [talledLocalContainer] ----
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] ----

[INFO] [talledLocalContainer] FTL stack trace ("~" means nesting-related):
[INFO] [talledLocalContainer]  - Failed at: #if document.introduction??  [in template "webfile:/freemarker/catalog/banner.ftl" at line 26, column 17]
[INFO] [talledLocalContainer] ----
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] Java stack trace (for programmers):
[INFO] [talledLocalContainer] ----
[INFO] [talledLocalContainer] freemarker.core.InvalidReferenceException: [... Exception message was already printed; see it above ...]
[INFO] [talledLocalContainer]  at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:131)
[INFO] [talledLocalContainer]  at freemarker.core.UnexpectedTypeException.newDesciptionBuilder(UnexpectedTypeException.java:77)
[INFO] [talledLocalContainer]  at freemarker.core.UnexpectedTypeException.<init>(UnexpectedTypeException.java:40)
[INFO] [talledLocalContainer]  at freemarker.core.NonHashException.<init>(NonHashException.java:46)
[INFO] [talledLocalContainer]  at freemarker.core.Dot._eval(Dot.java:45)
[INFO] [talledLocalContainer]  at freemarker.core.Expression.eval(Expression.java:78)
[INFO] [talledLocalContainer]  at freemarker.core.ExistsExpression._eval(ExistsExpression.java:45)
[INFO] [talledLocalContainer]  at freemarker.core.Expression.eval(Expression.java:78)
[INFO] [talledLocalContainer]  at freemarker.core.Expression.evalToBoolean(Expression.java:124)
[INFO] [talledLocalContainer]  at freemarker.core.Expression.evalToBoolean(Expression.java:110)
[INFO] [talledLocalContainer]  at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:46)
[INFO] [talledLocalContainer]  at freemarker.core.Environment.visit(Environment.java:324)
[INFO] [talledLocalContainer]  at freemarker.core.MixedContent.accept(MixedContent.java:54)
[INFO] [talledLocalContainer]  at freemarker.core.Environment.visit(Environment.java:324)
[INFO] [talledLocalContainer]  at freemarker.core.Environment.process(Environment.java:302)
[INFO] [talledLocalContainer]  at freemarker.template.Template.process(Template.java:325)
[INFO] [talledLocalContainer]  at freemarker.ext.servlet.FreemarkerServlet.process(FreemarkerServlet.java:725)
[INFO] [talledLocalContainer]  at freemarker.ext.servlet.FreemarkerServlet.doGet(FreemarkerServlet.java:642)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.servlet.HstFreemarkerServlet.doGet(HstFreemarkerServlet.java:184)
[INFO] [talledLocalContainer]  at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
[INFO] [talledLocalContainer]  at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:584)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:523)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstComponentInvokerImpl.invokeDispatcher(HstComponentInvokerImpl.java:418)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstComponentInvokerImpl.invokeRender(HstComponentInvokerImpl.java:218)
[INFO] [talledLocalContainer]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO] [talledLocalContainer]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[INFO] [talledLocalContainer]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[INFO] [talledLocalContainer]  at java.lang.reflect.Method.invoke(Method.java:497)
[INFO] [talledLocalContainer]  at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
[INFO] [talledLocalContainer]  at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
[INFO] [talledLocalContainer]  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
[INFO] [talledLocalContainer]  at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.PersistableSessionAroundAdvice.invoke(PersistableSessionAroundAdvice.java:68)
[INFO] [talledLocalContainer]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO] [talledLocalContainer]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[INFO] [talledLocalContainer]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[INFO] [talledLocalContainer]  at java.lang.reflect.Method.invoke(Method.java:497)
[INFO] [talledLocalContainer]  at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
[INFO] [talledLocalContainer]  at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
[INFO] [talledLocalContainer]  at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
[INFO] [talledLocalContainer]  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer]  at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.logging.HstComponentInvokerProfiler.profile(HstComponentInvokerProfiler.java:60)
[INFO] [talledLocalContainer]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO] [talledLocalContainer]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[INFO] [talledLocalContainer]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[INFO] [talledLocalContainer]  at java.lang.reflect.Method.invoke(Method.java:497)
[INFO] [talledLocalContainer]  at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
[INFO] [talledLocalContainer]  at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
[INFO] [talledLocalContainer]  at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
[INFO] [talledLocalContainer]  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer]  at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
[INFO] [talledLocalContainer]  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer]  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
[INFO] [talledLocalContainer]  at com.sun.proxy.$Proxy29.invokeRender(Unknown Source)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.AggregationValve.processWindowsRender(AggregationValve.java:434)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.AggregationValve.invoke(AggregationValve.java:234)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:269)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.ComponentRenderingValve.invoke(ComponentRenderingValve.java:34)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:269)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.PageCachingValve.invoke(PageCachingValve.java:64)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:269)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.ESIPageInfoScanningValve.invoke(ESIPageInfoScanningValve.java:79)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:269)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.PageInfoRenderingValve.invoke(PageInfoRenderingValve.java:50)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:269)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.ResourceServingValve.invoke(ResourceServingValve.java:40)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:269)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.ActionValve.invoke(ActionValve.java:48)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:269)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.LocalizationValve.invoke(LocalizationValve.java:96)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:269)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.ContextResolvingValve.invoke(ContextResolvingValve.java:101)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:269)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.JCRSessionStatefulConcurrencyValve.invoke(JCRSessionStatefulConcurrencyValve.java:56)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:269)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.SubjectBasedSessionValve.invoke(SubjectBasedSessionValve.java:58)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:269)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.SecurityValve.invoke(SecurityValve.java:177)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:269)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.CmsSecurityValve.invoke(CmsSecurityValve.java:82)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:269)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.InitializationValve.invoke(InitializationValve.java:50)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline$Invocation.invokeNext(HstSitePipeline.java:269)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline.invokeValves(HstSitePipeline.java:170)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstSitePipeline.invoke(HstSitePipeline.java:153)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.core.container.HstRequestProcessorImpl.processRequest(HstRequestProcessorImpl.java:79)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.container.HstDelegateeFilterBean.processResolvedSiteMapItem(HstDelegateeFilterBean.java:638)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.container.HstDelegateeFilterBean.doFilter(HstDelegateeFilterBean.java:351)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.container.DelegatingFilter.doFilter(DelegatingFilter.java:84)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.container.HstFilter.doFilter(HstFilter.java:51)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[INFO] [talledLocalContainer]  at org.hippoecm.hst.container.XSSUrlFilter.doFilter(XSSUrlFilter.java:52)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[INFO] [talledLocalContainer]  at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
[INFO] [talledLocalContainer]  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:106)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
[INFO] [talledLocalContainer]  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:142)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
[INFO] [talledLocalContainer]  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
[INFO] [talledLocalContainer]  at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
[INFO] [talledLocalContainer]  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
[INFO] [talledLocalContainer]  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
[INFO] [talledLocalContainer]  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
[INFO] [talledLocalContainer]  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
[INFO] [talledLocalContainer]  at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
[INFO] [talledLocalContainer]  at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
[INFO] [talledLocalContainer]  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[INFO] [talledLocalContainer]  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[INFO] [talledLocalContainer]  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
[INFO] [talledLocalContainer]  at java.lang.Thread.run(Thread.java:745)

Martijn van der Vorst

unread,
Nov 13, 2015, 7:34:22 AM11/13/15
to Hippo Community
Hello Woonsan,

Thanks for the help,

it turns out the problem was not in the compoundMacros, but rather in the menuMacros which I imported as "menu".
sadly that means it's confusing itself in freemarker with the item "menu" which is set by the EssentialsMenuComponent.

renaming the namespace fixed it.

Kind regards,
Martijn van der Vorst

Woonsan Ko

unread,
Nov 13, 2015, 7:40:22 AM11/13/15
to hippo-c...@googlegroups.com
Thank you so much for the update and great see it working! :-)
That's indeed sad to see how difficult it was to narrow it down.

Cheers,

Woonsan


--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
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/d/optout.

Martijn van der Vorst

unread,
Nov 13, 2015, 7:58:57 AM11/13/15
to Hippo Community
It's unusual to me, coming from a JSP background, to see the macro namespaces living in the same stack (so to speak) as the Java Objects that are set on the request.
This means we're going to need to be very careful with our macros and request variables, since the variables will overwrite the macros.
Reply all
Reply to author
Forward
0 new messages