简体   繁体   English

使用速度嵌套模板

[英]nested templates using velocity

I have a small java web project which should create a few web pages. 我有一个小的Java Web项目,应该创建几个网页。

All pages should have the same boilerplate (css, javascript, etc.) but indiviual content (ie the content of the main div.) 所有页面都应具有相同的样板(css,javascript等),但要包含单独的内容(即主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. 目前,我看到的唯一方法是渲染样板模板,该模板使用#parse包含作为上下文参数给出的实际页面。

Is there an easier way? 有更容易的方法吗?

I come from sinatra where you render the actual page and implicitly add the boilerplate around it. 我来自sinatra ,您在其中渲染实际页面并在其周围隐式添加样板。 Do you know of any similar templating framework in Java? 您知道Java中有任何类似的模板框架吗?

In sinatra you could for example do: 在sinatra中,您可以例如执行以下操作:

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.) (或通过在默认布局中忽略布局部分。)

我建议您使用VelocityTools项目中的VelocityLayoutServlet: http : //velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/view/VelocityLayoutServlet.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM