michas
michas

Reputation: 26545

nested templates using velocity

I have a small java web project which should create a few web pages.

All pages should have the same boilerplate (css, javascript, etc.) but indiviual content (i.e. the content of the main div.)

What is the usual way of implementing this kind of setup in velocity?

Currently the only way I see is rendering the boilerplate template which uses #parse to include the actual page which is given as a context parameter.

Is there an easier way?

I come from sinatra where you render the actual page and implicitly add the boilerplate around it. Do you know of any similar templating framework in Java?

In sinatra you could for example do:

get '/' do
  haml :index, :layout => :master
end

to render the index page in the master layout. (Or by leaving out the layout part in the default layout.)

Upvotes: 0

Views: 1498

Answers (1)

Nathan Bubna
Nathan Bubna

Reputation: 6933

I'd recommend you use the VelocityLayoutServlet from the VelocityTools project: http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/view/VelocityLayoutServlet.html

Upvotes: 2

Related Questions