You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Ben Short <be...@benshort.co.uk> on 2010/03/12 12:06:05 UTC

Possible with Velocity

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>

Is it possible todo the same with velocity?

Regards

Ben

RE: Check to see if macro defined

Posted by Steve O'Hara <so...@pivotal-solutions.co.uk>.
Excellent idea Nathan - I implemented #ismacrodefined and #ismacronotdefined and it worked perfectly.

Many thanks,

Steve

-----Original Message-----
From: Nathan Bubna [mailto:nbubna@gmail.com] 
Sent: 14 September 2010 17:52
To: Velocity Users List
Subject: Re: Check to see if macro defined

Yeah, the parser is not likely to smile upon new syntaxes.  However,
you have given me an idea.  Custom directives have access to
RuntimeServices, which does expose the isVelocimacro function.  So you
ought to be able to create a custom block directive that works like
this:


#ismacrodefined( 'mymacro' )

use the macro or whatever here...

#end

On Tue, Sep 14, 2010 at 9:14 AM, Steve O'Hara
<so...@pivotal-solutions.co.uk> wrote:
> Hi Nathan,
>
> I thought that might be the case although I rather like the idea of the quiet notation idea.
> Is it possible to create a custom directive that subclasses macro called "!macro" or will the parser/lexer not find these?
>
> Thanks
> Steve
>
> -----Original Message-----
> From: Nathan Bubna [mailto:nbubna@gmail.com]
> Sent: 14 September 2010 15:46
> To: Velocity Users List
> Subject: Re: Check to see if macro defined
>
> You'd have to hack Velocity to do it cleanly.  There's currently no
> way to test that in the template.  RuntimeInstance has an
> isVelocimacro(name, templateName) method, but it is not even exposed
> in VelocityEngine, much less in the template.
>
> On Tue, Sep 14, 2010 at 5:12 AM, Steve O'Hara
> <so...@pivotal-solutions.co.uk> wrote:
>> We have a number of macro libraries that are used across projects.
>> We need to change some of the 'general' macros so that they will
>> optionally make a call to a 'project' macro if it exists.
>> For example;
>>
>> #macro(outputLabel $Field)
>>   #set ($Label=$Field.getLabel())
>>   #if (#projectOutputLabel is Defined)
>>       #projectOutputLabel($Field)
>>   #end
>>   $Label
>> #end
>>
>> May be not a very good example but you get the idea.  Perhaps a way to
>> implement it if there isn't a way already would be to enable the quiet
>> syntax using the exclamation mark e.g.
>>
>> #macro(outputLabel $Field)
>>   #set ($Label=$Field.getLabel())
>>   #!projectOutputLabel($Field)
>>   $Label
>> #end
>>
>> Any ideas?
>>
>> Thanks,
>>
>> Steve
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Check to see if macro defined

Posted by Nathan Bubna <nb...@gmail.com>.
Yeah, the parser is not likely to smile upon new syntaxes.  However,
you have given me an idea.  Custom directives have access to
RuntimeServices, which does expose the isVelocimacro function.  So you
ought to be able to create a custom block directive that works like
this:


#ismacrodefined( 'mymacro' )

use the macro or whatever here...

#end

On Tue, Sep 14, 2010 at 9:14 AM, Steve O'Hara
<so...@pivotal-solutions.co.uk> wrote:
> Hi Nathan,
>
> I thought that might be the case although I rather like the idea of the quiet notation idea.
> Is it possible to create a custom directive that subclasses macro called "!macro" or will the parser/lexer not find these?
>
> Thanks
> Steve
>
> -----Original Message-----
> From: Nathan Bubna [mailto:nbubna@gmail.com]
> Sent: 14 September 2010 15:46
> To: Velocity Users List
> Subject: Re: Check to see if macro defined
>
> You'd have to hack Velocity to do it cleanly.  There's currently no
> way to test that in the template.  RuntimeInstance has an
> isVelocimacro(name, templateName) method, but it is not even exposed
> in VelocityEngine, much less in the template.
>
> On Tue, Sep 14, 2010 at 5:12 AM, Steve O'Hara
> <so...@pivotal-solutions.co.uk> wrote:
>> We have a number of macro libraries that are used across projects.
>> We need to change some of the 'general' macros so that they will
>> optionally make a call to a 'project' macro if it exists.
>> For example;
>>
>> #macro(outputLabel $Field)
>>   #set ($Label=$Field.getLabel())
>>   #if (#projectOutputLabel is Defined)
>>       #projectOutputLabel($Field)
>>   #end
>>   $Label
>> #end
>>
>> May be not a very good example but you get the idea.  Perhaps a way to
>> implement it if there isn't a way already would be to enable the quiet
>> syntax using the exclamation mark e.g.
>>
>> #macro(outputLabel $Field)
>>   #set ($Label=$Field.getLabel())
>>   #!projectOutputLabel($Field)
>>   $Label
>> #end
>>
>> Any ideas?
>>
>> Thanks,
>>
>> Steve
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


RE: Check to see if macro defined

Posted by Steve O'Hara <so...@pivotal-solutions.co.uk>.
Hi Nathan,

I thought that might be the case although I rather like the idea of the quiet notation idea.
Is it possible to create a custom directive that subclasses macro called "!macro" or will the parser/lexer not find these?

Thanks
Steve

-----Original Message-----
From: Nathan Bubna [mailto:nbubna@gmail.com] 
Sent: 14 September 2010 15:46
To: Velocity Users List
Subject: Re: Check to see if macro defined

You'd have to hack Velocity to do it cleanly.  There's currently no
way to test that in the template.  RuntimeInstance has an
isVelocimacro(name, templateName) method, but it is not even exposed
in VelocityEngine, much less in the template.

On Tue, Sep 14, 2010 at 5:12 AM, Steve O'Hara
<so...@pivotal-solutions.co.uk> wrote:
> We have a number of macro libraries that are used across projects.
> We need to change some of the 'general' macros so that they will
> optionally make a call to a 'project' macro if it exists.
> For example;
>
> #macro(outputLabel $Field)
>   #set ($Label=$Field.getLabel())
>   #if (#projectOutputLabel is Defined)
>       #projectOutputLabel($Field)
>   #end
>   $Label
> #end
>
> May be not a very good example but you get the idea.  Perhaps a way to
> implement it if there isn't a way already would be to enable the quiet
> syntax using the exclamation mark e.g.
>
> #macro(outputLabel $Field)
>   #set ($Label=$Field.getLabel())
>   #!projectOutputLabel($Field)
>   $Label
> #end
>
> Any ideas?
>
> Thanks,
>
> Steve
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Check to see if macro defined

Posted by Nathan Bubna <nb...@gmail.com>.
You'd have to hack Velocity to do it cleanly.  There's currently no
way to test that in the template.  RuntimeInstance has an
isVelocimacro(name, templateName) method, but it is not even exposed
in VelocityEngine, much less in the template.

On Tue, Sep 14, 2010 at 5:12 AM, Steve O'Hara
<so...@pivotal-solutions.co.uk> wrote:
> We have a number of macro libraries that are used across projects.
> We need to change some of the 'general' macros so that they will
> optionally make a call to a 'project' macro if it exists.
> For example;
>
> #macro(outputLabel $Field)
>   #set ($Label=$Field.getLabel())
>   #if (#projectOutputLabel is Defined)
>       #projectOutputLabel($Field)
>   #end
>   $Label
> #end
>
> May be not a very good example but you get the idea.  Perhaps a way to
> implement it if there isn't a way already would be to enable the quiet
> syntax using the exclamation mark e.g.
>
> #macro(outputLabel $Field)
>   #set ($Label=$Field.getLabel())
>   #!projectOutputLabel($Field)
>   $Label
> #end
>
> Any ideas?
>
> Thanks,
>
> Steve
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Check to see if macro defined

Posted by Steve O'Hara <so...@pivotal-solutions.co.uk>.
We have a number of macro libraries that are used across projects.
We need to change some of the 'general' macros so that they will
optionally make a call to a 'project' macro if it exists.
For example;

#macro(outputLabel $Field)
   #set ($Label=$Field.getLabel())
   #if (#projectOutputLabel is Defined)
       #projectOutputLabel($Field)
   #end
   $Label
#end

May be not a very good example but you get the idea.  Perhaps a way to
implement it if there isn't a way already would be to enable the quiet
syntax using the exclamation mark e.g.

#macro(outputLabel $Field)
   #set ($Label=$Field.getLabel())
   #!projectOutputLabel($Field)
   $Label
#end 

Any ideas?

Thanks,

Steve

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Possible with Velocity

Posted by Ben Short <be...@benshort.co.uk>.
Jarkko,

Thanks that's exactly what I was looking for. Any ideas on when 1.7 will be
released?

Regards

Ben

2010/3/13 Jarkko Viinamäki-2 <wy...@sci.fi>

>
> 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: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

Re: Possible with Velocity

Posted by Jarkko Viinamäki-2 <wy...@sci.fi>.
Hi Ben,

Sorry I made a mistake in my example. Macro invocations with AST body need
the @ char like this:

#@layout()
This is the body content!!
#end

-- 
View this message in context: http://old.nabble.com/Possible-with-Velocity-tp27875992p27906759.html
Sent from the Velocity - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Possible with Velocity

Posted by Ben Short <be...@benshort.co.uk>.
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 <wy...@sci.fi>

>
> 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: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

Re: Possible with Velocity

Posted by Jarkko Viinamäki-2 <wy...@sci.fi>.
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: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Possible with Velocity

Posted by Ben Short <be...@benshort.co.uk>.
Charlie,

Thanks for the information. Even feels a little cleaner doing it this way.

Ben

On 12 March 2010 15:57, Charles Harvey III <ch...@alloy.com> wrote:

> Ben,
> Use the VelocityLayoutServlet in your web.xml.
> Actually, if it were only Velocity than that would be the solution.  But
> since you have
> Spring here is the setup:
>
>
> /WEB-INF/applicationContext.xml
>
> ----------------------------------------------------------------------------------------------------------
> <beans>
>    <bean id="velocityConfigurer"
> class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
>        <property name="resourceLoaderPath" value="/"/>
>        <property name="configLocation"
> value="/WEB-INF/velocity.properties"/>
>    </bean>
> </beans>
>
> ----------------------------------------------------------------------------------------------------------
>
>
> /WEB-INF/abc-servlet.xml
>
> ----------------------------------------------------------------------------------------------------------
> <beans>
>    <bean id="viewResolver"
>
> class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
>        <property name="viewClass"
> value="org.springframework.web.servlet.view.velocity.VelocityLayoutView"/>
>        <property name="cache" value="true"/>
>        <property name="prefix" value=""/>
>        <property name="suffix" value=".vm"/>
>        <property name="exposeRequestAttributes" value="true"/>
>        <property name="exposeSessionAttributes" value="true"/>
>        <property name="exposeSpringMacroHelpers" value="true"/>
>        <property name="layoutUrl" value="/layout/default_layout.vm"/>
>        <property name="toolboxConfigLocation"
> value="/WEB-INF/toolbox.xml"/>
>    </bean>
> </beans>
>
> ----------------------------------------------------------------------------------------------------------
>
>
> /WEB-INF/velocity.properties (include this anywhere)
>
> ----------------------------------------------------------------------------------------------------------
>
> #----------------------------------------------------------------------------
> # LAYOUT SERVLET MANAGEMENT
>
> #----------------------------------------------------------------------------
> # Allows for screens to be used for layout
>
> #----------------------------------------------------------------------------
> # Filepath for error template, relative to web application root directory
> tools.view.servlet.error.template = /layout/layout_error.vm
>
> # Directory for layout templates, relative to web application root
> directory
> tools.view.servlet.layout.directory = /layout/
>
> # Filepath of the default layout template
> # relative to the layout directory
> # NOT relative to the root directory of the webapp!
> tools.view.servlet.layout.default.template = default_layout.vm
>
> ----------------------------------------------------------------------------------------------------------
>
>
> /layout/default_layout.vm
>
> ----------------------------------------------------------------------------------------------------------
> <?xml version="1.0" encoding="utf-8"?>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
>
>    #parse( "/includes/header.vm" )
>
>    <body>
>
>        #parse( "/includes/navigation.vm" )
>
>
> $!{screen_content}
>
>
>        #parse( "/includes/footer.vm" )
>
>
>    </body>
>
> </html>
>
> ----------------------------------------------------------------------------------------------------------
>
>
> The default_layout.vm is a wrapper file.
> The call goes like so:
>  - home.htm -> HomeController
>  - HomeController -> return new ModelAndView( "/home.vm" )
>  - /home.vm -> set any variables
>  - VelocityLayoutViewResolver -> wrap home.vm with default_layout.vm
>  - show page
>
>
> Hopefully this was all the information you needed to get going.  I've
> been using this setup for years.
>
>
>
> Charlie
>
>
>
>
> On 03/12/2010 10:12 AM, Ben Short wrote:
> > Hi Malcom,
> >
> > Yes I have thought about that pattern.
> >
> > I'm using spring mvc so that way of doing it wont work for me. What I
> don't
> > want to have to do is
> >
> > #parse('header.vm')
> > <div>
> >       <h1>Standard Page</h1>
> >   </div>
> > #parse('footer.vm')
> >
> > As cutting a designed page up can be tricky.
> >
> > Ben
> >
> > On 12 March 2010 11:16, Malcolm Edgar <ma...@gmail.com> wrote:
> >
> >
> >> In Apache Click we use a similar pattern using Velocity.
> >>
> >>
> >>
> http://click.apache.org/docs/user-guide/htmlsingle/click-book.html#page-templating
> >>
> >> regards Malcolm Edgar
> >>
> >> On Fri, Mar 12, 2010 at 10:06 PM, Ben Short <be...@benshort.co.uk> 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>
> >>>
> >>> Is it possible todo the same with velocity?
> >>>
> >>> Regards
> >>>
> >>> Ben
> >>>
> >>>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> >> For additional commands, e-mail: user-help@velocity.apache.org
> >>
> >>
> >>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

Re: Possible with Velocity

Posted by Charles Harvey III <ch...@alloy.com>.
Ben,
Use the VelocityLayoutServlet in your web.xml.
Actually, if it were only Velocity than that would be the solution.  But
since you have
Spring here is the setup:


/WEB-INF/applicationContext.xml
----------------------------------------------------------------------------------------------------------
<beans>
    <bean id="velocityConfigurer"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="resourceLoaderPath" value="/"/>
        <property name="configLocation"
value="/WEB-INF/velocity.properties"/>
    </bean>
</beans>
----------------------------------------------------------------------------------------------------------


/WEB-INF/abc-servlet.xml
----------------------------------------------------------------------------------------------------------
<beans>
    <bean id="viewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
        <property name="viewClass"
value="org.springframework.web.servlet.view.velocity.VelocityLayoutView"/>
        <property name="cache" value="true"/>
        <property name="prefix" value=""/>
        <property name="suffix" value=".vm"/>
        <property name="exposeRequestAttributes" value="true"/>
        <property name="exposeSessionAttributes" value="true"/>
        <property name="exposeSpringMacroHelpers" value="true"/>
        <property name="layoutUrl" value="/layout/default_layout.vm"/>
        <property name="toolboxConfigLocation"
value="/WEB-INF/toolbox.xml"/>
    </bean>
</beans>
----------------------------------------------------------------------------------------------------------


/WEB-INF/velocity.properties (include this anywhere)
----------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------
# LAYOUT SERVLET MANAGEMENT
#----------------------------------------------------------------------------
# Allows for screens to be used for layout
#----------------------------------------------------------------------------
# Filepath for error template, relative to web application root directory
tools.view.servlet.error.template = /layout/layout_error.vm

# Directory for layout templates, relative to web application root directory
tools.view.servlet.layout.directory = /layout/

# Filepath of the default layout template
# relative to the layout directory
# NOT relative to the root directory of the webapp!
tools.view.servlet.layout.default.template = default_layout.vm
----------------------------------------------------------------------------------------------------------


/layout/default_layout.vm
----------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

    #parse( "/includes/header.vm" )

    <body>

        #parse( "/includes/navigation.vm" )


$!{screen_content}


        #parse( "/includes/footer.vm" )


    </body>

</html>
----------------------------------------------------------------------------------------------------------


The default_layout.vm is a wrapper file.
The call goes like so:
 - home.htm -> HomeController
 - HomeController -> return new ModelAndView( "/home.vm" )
 - /home.vm -> set any variables
 - VelocityLayoutViewResolver -> wrap home.vm with default_layout.vm
 - show page


Hopefully this was all the information you needed to get going.  I've
been using this setup for years.



Charlie




On 03/12/2010 10:12 AM, Ben Short wrote:
> Hi Malcom,
>
> Yes I have thought about that pattern.
>
> I'm using spring mvc so that way of doing it wont work for me. What I don't
> want to have to do is
>
> #parse('header.vm')
> <div>
>       <h1>Standard Page</h1>
>   </div>
> #parse('footer.vm')
>
> As cutting a designed page up can be tricky.
>
> Ben
>
> On 12 March 2010 11:16, Malcolm Edgar <ma...@gmail.com> wrote:
>
>   
>> In Apache Click we use a similar pattern using Velocity.
>>
>>
>> http://click.apache.org/docs/user-guide/htmlsingle/click-book.html#page-templating
>>
>> regards Malcolm Edgar
>>
>> On Fri, Mar 12, 2010 at 10:06 PM, Ben Short <be...@benshort.co.uk> 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>
>>>
>>> Is it possible todo the same with velocity?
>>>
>>> Regards
>>>
>>> Ben
>>>
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>>     
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Possible with Velocity

Posted by Will Glass-Husain <wg...@gmail.com>.
Hi,

You can do this with Spring MVC Framework using the VelocityLayoutServlet.

Specifically, configure your site with the Spring
VelocityLayoutViewResolver.

http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/web/servlet/view/velocity/VelocityLayoutViewResolver.html

WILL

On Fri, Mar 12, 2010 at 7:12 AM, Ben Short <be...@benshort.co.uk> wrote:

> Hi Malcom,
>
> Yes I have thought about that pattern.
>
> I'm using spring mvc so that way of doing it wont work for me. What I don't
> want to have to do is
>
> #parse('header.vm')
> <div>
>      <h1>Standard Page</h1>
>  </div>
> #parse('footer.vm')
>
> As cutting a designed page up can be tricky.
>
> Ben
>
> On 12 March 2010 11:16, Malcolm Edgar <ma...@gmail.com> wrote:
>
> > In Apache Click we use a similar pattern using Velocity.
> >
> >
> >
> http://click.apache.org/docs/user-guide/htmlsingle/click-book.html#page-templating
> >
> > regards Malcolm Edgar
> >
> > On Fri, Mar 12, 2010 at 10:06 PM, Ben Short <be...@benshort.co.uk> 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>
> > >
> > > Is it possible todo the same with velocity?
> > >
> > > Regards
> > >
> > > Ben
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> > For additional commands, e-mail: user-help@velocity.apache.org
> >
> >
>

Re: Possible with Velocity

Posted by Ben Short <be...@benshort.co.uk>.
Hi Malcom,

Yes I have thought about that pattern.

I'm using spring mvc so that way of doing it wont work for me. What I don't
want to have to do is

#parse('header.vm')
<div>
      <h1>Standard Page</h1>
  </div>
#parse('footer.vm')

As cutting a designed page up can be tricky.

Ben

On 12 March 2010 11:16, Malcolm Edgar <ma...@gmail.com> wrote:

> In Apache Click we use a similar pattern using Velocity.
>
>
> http://click.apache.org/docs/user-guide/htmlsingle/click-book.html#page-templating
>
> regards Malcolm Edgar
>
> On Fri, Mar 12, 2010 at 10:06 PM, Ben Short <be...@benshort.co.uk> 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>
> >
> > Is it possible todo the same with velocity?
> >
> > Regards
> >
> > Ben
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

Re: Possible with Velocity

Posted by Malcolm Edgar <ma...@gmail.com>.
In Apache Click we use a similar pattern using Velocity.

http://click.apache.org/docs/user-guide/htmlsingle/click-book.html#page-templating

regards Malcolm Edgar

On Fri, Mar 12, 2010 at 10:06 PM, Ben Short <be...@benshort.co.uk> 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>
>
> Is it possible todo the same with velocity?
>
> Regards
>
> Ben
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org