Introduction

This Velocity guide is intended to help us code with Apache Velocity and dotCMS.

Velocity is a Java-based template engine. It permits web page designers to reference methods defined in Java code. Web designers can work in parallel with Java programmers to develop web sites according to the Model-View-Controller (MVC) model, meaning that web page designers can focus solely on creating a well-designed site, and programmers can focus solely on writing top-notch code. Velocity separates Java code from the web pages, making the web site more maintainable over the long run and providing a viable alternative to Java Server Pages (JSPs) or PHP.

Velocity can be used to generate web pages, SQL, PostScript and other output from templates. It can be used either as a standalone utility for generating source code and reports, or as an integrated component of other systems. When complete, Velocity will provide template services for the Turbine web application framework. Velocity+Turbine will provide a template service that will allow web applications to be developed according to a true MVC model.

This website has quite a lot of tips and tricks that you may only use rarely

Here is an example piece of code you would commonly use - it generates a list based on the content type which is extracted from the querystring:

Good Luck.

  1. ## Get Type from querystring  
  2. #set ($type = $request.getParameter('type'))  
  3.   
  4. #if($UtilMethods.isSet($type))  
  5.       #set ($queryType = "+YOURSTRUCTURENAME.type1:$!{type}")  
  6. #end  
  7.   
  8. #set ($list = $dotcontent.pull("+structureName:YOURSTRUCTURENAME $queryType",0,"modDate desc"))   
  9.   
  10. #if ($list.size() > 0)   
  11.       <ul>  
  12.             #foreach($item in $list)   
  13.                   <li>$item.title</li>  
  14.             #end   
  15.       </ul>  
  16. #end  
comments powered by Disqus