Chris Sainty

A technical blog covering full-stack web development.

twitter | github | stackoverflow

Veil - Getting Started With Nancy

Nancy is a great framework for building websites and it has been an important goal for Veil to integrate seamlessly in to your Nancy projects.

To get started you will first need to install Veil's view engine wrapper for Nancy.

Install-Package Nancy.ViewEngines.Veil

You also need to install one or more Veil parsers.

Nancy and Veil then work together to wire everything up with no other changes. Unlike razor there are no mysterious web.config changes to make.

Be default Veil will handle templates with following extensions.

For more details on the supported syntax of each parser check out their projects on GitHub. Veil.SuperSimple Veil.Handlebars

How to get Veil to handle .sshtml templates?

If you would like to use Veil to handle .sshtml templates that were previously being handled by Nancy's own SuperSimpleViewEngine then you need to unregister it in your bootstrapper.

public class CustomBootstrapper : DefaultNancyBootstrapper
{
    protected override IEnumerable<Type> ViewEngines
    {
        get
        {
            return new[] { typeof(Nancy.ViewEngines.Veil.VeilViewEngine) };
        }
    }
}

How to get Veil to handle arbitrary template extensions?

If you like to register an arbitrary file extension to a Veil parser, say .html to the Handlebars parser. You simply need to drop in an ITemplateParserRegistration which Veil will detect on startup.

public class CustomParserRegistration : ITemplateParserRegistration
{
    public IEnumerable<string> Keys { get { return new[] { "html" }; } }

    public Func<ITemplateParser> ParserFactory
    {
        get { return () => new HandlebarsParser(); }
    }
}