Home

Castle Stronghold

Table of contents

  • 1 NVelocity files
  • 2 Layouts
  • 3 Configuring NVelocity
  • 4 Macros
  • 5 WebForms vs NVelocity

NVelocity View Engine

The NVelocity View Engine uses NVelocity

Frequently Asked Questions on NVelocity View Engine can be found on the standard MonoRail FAQ.

To use NVelocity View Engine inform the type on the customEngine on the configuration file:


<viewEngine 
    viewPathRoot="views" 
    customEngine="Castle.MonoRail.Framework.Views.NVelocity.NVelocityViewEngine, Castle.MonoRail.Framework.Views.NVelocity" />

NVelocity files

NVelocity uses the extension .vm so just create your views with that extension. Remember that from your controller you should not reference file extensions when defining views to render.

Layouts

Use $childContent context variable to render the content of the view on the layout template. The following is a simple layout using NVelocity:


<html>

Welcome

$childContent

Footer

</html>
    
Quick Note

The view template selected by the controller is executed before the layout template. In fact the layout template is merged with the result of the view template execution.

Configuring NVelocity

The NVelocity View Engine looks for a file nvelocity.properties in the root of the view folder. You can use this file to configure how NVelocity should behave.

For example, to configure NVelocity to support Chinese enconding create a text file named nvelocity.properties, save it to your views folder and add the following content:

input.encoding=GB2312
output.encoding=GB2312

More information on the entries can be found on the original Velocity documentation.

Macros

The NVelocity supports macro, and have in mind they have problems. If you want to use macros you can create a folder macros under the your views root folder

All .vm files in this folder will be loaded as NVelocity Macro library so the macros will be available to all templates.

WebForms vs NVelocity

There is a common FUD in moving from WebForms to NVelocity. NVelocity promotes a better separation of concerns than WebForms (the issues with WebForms are stated in the Asp.Net View Engine document).

So try NVelocity View Engine with a small project that demands common tasks like pagination, authentication and make your own conclusions.

Google
Search WWW Search castleproject.org