Hi I have setup the following files and am using the latest 1.7 snapshot
from here
http://people.apache.org/repo/m2-snapshot-repository/org/apache/velocity/velocity/1.7-SNAPSHOT/
layout.vm
#macro(layout)
<html>
<head>
<title>Test</title>
</head>
<body>
<h1>Title</h1>
$bodyContent
</body>
</html>
#end
page.vm
#parse("layout.vm")
#layout()
This is the body content!!
#end
When I run my application and request the page I get the following exception
org.springframework.core.NestedIOException: Could not load Velocity template
for URL [page.vm]; nested exception is
org.apache.velocity.exception.ParseErrorException: Encountered "#end" at
page.vm[line 4, column 1]
Was expecting one of:
<EOF>
"(" ...
<RPAREN> ...
<ESCAPE_DIRECTIVE> ...
<SET_DIRECTIVE> ...
"##" ...
"\\\\" ...
"\\" ...
<TEXT> ...
"*#" ...
"*#" ...
"]]#" ...
<STRING_LITERAL> ...
<IF_DIRECTIVE> ...
<INTEGER_LITERAL> ...
<FLOATING_POINT_LITERAL> ...
<WORD> ...
<BRACKETED_WORD> ...
<IDENTIFIER> ...
<DOT> ...
"{" ...
"}" ...
<EMPTY_INDEX> ...
at
org.springframework.web.servlet.view.velocity.VelocityView.checkResource(VelocityView.java:270)
at
org.springframework.web.servlet.view.velocity.VelocityLayoutView.checkResource(VelocityLayoutView.java:123)
at
org.springframework.web.servlet.view.UrlBasedViewResolver.loadView(UrlBasedViewResolver.java:421)
at
org.springframework.web.servlet.view.AbstractCachingViewResolver.createView(AbstractCachingViewResolver.java:158)
at
org.springframework.web.servlet.view.UrlBasedViewResolver.createView(UrlBasedViewResolver.java:384)
at
org.springframework.web.servlet.view.AbstractCachingViewResolver.resolveViewName(AbstractCachingViewResolver.java:77)
at
org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1091)
at
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1040)
at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
at
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.velocity.exception.ParseErrorException: Encountered
"#end" at page.vm[line 4, column 1]
Was expecting one of:
<EOF>
"(" ...
<RPAREN> ...
<ESCAPE_DIRECTIVE> ...
<SET_DIRECTIVE> ...
"##" ...
"\\\\" ...
"\\" ...
<TEXT> ...
"*#" ...
"*#" ...
"]]#" ...
<STRING_LITERAL> ...
<IF_DIRECTIVE> ...
<INTEGER_LITERAL> ...
<FLOATING_POINT_LITERAL> ...
<WORD> ...
<BRACKETED_WORD> ...
<IDENTIFIER> ...
<DOT> ...
"{" ...
"}" ...
<EMPTY_INDEX> ...
at org.apache.velocity.Template.process(Template.java:151)
at
org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:437)
at
org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:352)
at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1520)
at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1501)
at
org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:373)
at
org.springframework.web.servlet.view.velocity.VelocityView.getTemplate(VelocityView.java:501)
at
org.springframework.web.servlet.view.velocity.VelocityView.checkResource(VelocityView.java:260)
... 25 more
2010/3/13 Jarkko Viinamäki-2 <[email protected]>
>
> Unreleased Velocity 1.7 (current SVN head) provides this kind of feature.
>
> A simple example using Velocity syntax:
>
> Declare this macro either in your macro library or parse it in via
> #parse("layoutmacro.vm") or similar
>
> #macro(layout)
> <html><body>$bodyContent</body></html>
> #end
>
> #layout()
> This is the content in bold
> #end
>
> would result in <html><body>This is the content in bold</body></html>
>
>
>
> Ref. https://issues.apache.org/jira/browse/VELOCITY-666
>
>
> benshort wrote:
> >
> > Hi,
> >
> > With free marker I can do the following:
> >
> > layout.ftl
> >
> > <#macro layout>
> > <html>
> > <head>
> > <title>Freemarker Test</title>
> > </head>
> > <body>
> > <h1></h1>
> > <#nested/>
> > </body>
> > </html>
> > </#macro>
> >
> > page.ftl
> >
> > <#import "layout.ftl" as layout>
> > <@layout.layout>
> > <div>
> > <h1>Standard Page</h1>
> > </div>
> > </@layout.layout>
> >
>
> --
> View this message in context:
> http://old.nabble.com/Possible-with-Velocity-tp27875992p27886180.html
> Sent from the Velocity - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>