Home

Castle Stronghold

Table of contents

  • 1 XHTML vs HTML
  • 2 Content

View Engines

View engines are responsible for rendering the contents back to the browser. You can create your view engine by simply implementing the interface IViewEngine. For example, you can create a XML/XSL view engine, or WML, or whatever you can think of. Notice however that the view should be responsible for displaying logic and nothing more, nothing less.

The view engine implementation is also supposed to invoke a few hooks on the controller instance, namely PreSendView and PostSendView.

Below is the declaration of the IViewEngine interface.


/// <summary>
/// Depicts the contract used by the engine
/// to process views, in an independent manner.
/// </summary>
public interface IViewEngine
{
    /// <summary>
    /// Evaluates whether the specified template exists.
    /// </summary>
    /// <returns><c>true</c> if it exists</returns>
    bool HasTemplate(String templateName);

    /// <summary>
    /// Processes the view - using the templateName 
    /// to obtain the correct template,
    /// and using the context to output the result.
    /// </summary>
    void Process(IRailsEngineContext context, Controller controller, String templateName);

    ///<summary>
    /// Processes the view - using the templateName 
    /// to obtain the correct template
    /// and writes the results to the System.TextWriter. 
    /// No layout is applied!
    /// </summary>
    void Process(TextWriter output, IRailsEngineContext context, Controller controller, String templateName);

    /// <summary>
    /// Wraps the specified content in the layout using 
    /// the context to output the result.
    /// </summary>
    void ProcessContents(IRailsEngineContext context, Controller controller, String contents);
}

XHTML vs HTML

By default the view engines will return pages with the MIME type text/html. If you would like to use application/xml+xhtml you can set this in your web.config file:


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

If this attribute is set to true, and the user agent says it will accept application/xml+xhtml then the page will be returned using that MIME type instead. For browsers such as IE which do not understand the new MIME type, text/html will still be used.

Content

Google
Search WWW Search castleproject.org