Charlie,

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

Ben

On 12 March 2010 15:57, Charles Harvey III <[email protected]> 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 <[email protected]> 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 <[email protected]> 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: [email protected]
> >> For additional commands, e-mail: [email protected]
> >>
> >>
> >>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to