Dashboard > Castle Contrib > Home > Castle.MonoRail.Views.NDjango
Log In   View a printable version of the current page.
Castle.MonoRail.Views.NDjango
Added by Michael Feingold, last edited by Michael Feingold on Dec 10, 2009  (view change)
Labels: 
(None)


Feature Overview

NDjango is an implementation of the Django Template Language on the .NET platform, using the F# language. It also includes an NDjango editor for VS2010 with full blown support for syntax colorization, code completion and the such.

Getting NDjango

You can get NDjango from the castle project contrib SVN: http://svn.castleproject.org:8080/svn/castlecontrib/viewengines/. You can get the source code from the src subfolder or the ready to use binaries from the bin subfolder. The src subfolder also has a sample NDJango project. For further details on how to integrate NDjango View Engine with Monorail follow this link. Keep in mind that the NDjango editor requires a separate setup to be found here

Crash Course

Templates

This is the content of the index page template from the NDjango sample:

{% extends "Common/base.django" %}

{% block Title %}
     New Template
{% endblock %}

{% block body %}
     Hello world. Test email:{{ testData.Email }} <br />
     Image example <img src ="{% url 'Content/images/mr.png' %}" border="0" />
{% endblock %}

The first line in the index page template indicates that it is inherited from another template called base.django.
Here is the content of the base template:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>
        {% block Title %}
            Base Title
        {% endblock %}
    </title>
</head>
<body>
<h3>This text comes from the base template.</h3>

Base text.

<h3>While following - from the inherited template.</h3>
{% block body %}
Base body.
{% endblock %}

</body>
</html>

Modifying data using filters

Sometimes a value as provided by the controller has to be adjusted, formatted, or modified in some way before it can be used in the template. In Django this is done by applying filters to the values. For instance If you have a DateTime timestamp on the email object the format the date

{{testData.Email.timestamp|date:"D d M y"}}

The output will look like "Thu 21 Dec 2000". Out of the box you get several dozens of standard filters and adding your own is also very simple

web.config setup

add Castle.MonoRail.Views.NDjangoView.NDjangoViewEngine, Castle.MonoRail.Views.NDjangoView to the viewengine configuration in config/monorail:

<monoRail>
...
 <viewEngines viewPathRoot="Views">
  <add xhtml="false" type="Castle.Monorail.Views.NDjangoView.NDjangoViewEngine, Castle.Monorail.Views.NDjangoView"/>
 </viewEngines>
...
</monoRail>

that's it.

You might also want to prevent direct browsing of django templates:

<system.web>
    ...
     <httpHandlers>
      ...
      <add verb="*" path="*.django" type="System.Web.HttpForbiddenHandler"/>

required dlls:

The references to the following dlls have to be added to your project:

  • Castle.Monorail.Views.NDjangoView.dll (0.9.0.0)
  • NDjango.Core.dll (0.9.6.0)
  • NDjangoFilters.NDjangoExtension.dll (0.9.6.0)
  • FSharp.Core.dll (2.0.0.0)
  • FSharp.PowerPack.dll (1.9.7.8)

You can find these dlls in the download

Site running on a free Atlassian Confluence Community License granted to Castle Project. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.4 Build:#809 Jun 12, 2007) - Bug/feature request - Contact Administrators