views:

406

answers:

1

Are there any differences, limitations or gotchas between NDjango and Django templates? I'm specifically interested in implementing them in future ASP.NET MVC projects.

I'm certain I won't be able to use any of my custom template tags that I've written for Django, but would I be able to port them to NDjango?

+3  A: 

yes, you would. you can extend the default tag and filter set by writing your own and registering them on application startup. there's only one thing to keep in mind - filters were meant to be very easily extended, and so there you just have to implement one of two straight-forward interfaces (ISimpleFilter for no-parameter filters or IFilter for filters with 1 parameter). For tags, the concept is the same, but since NDjango itself is written in F#, the ITag interface is a bit more difficult to consume from C# or VB. It's certainly doable, but a bit messy. From F#, it's very straightforward.

in f# it looks like this:

/// A single tag implementation
and ITag = 
    /// Transforms a {% %} tag into a list of nodes and uncommited token list
    member Perform: Lexer.BlockToken -> IParser -> 
             Lexer.Token seq -> (Node list * Lexer.Token seq)

in c#, it looks like this:

    public Tuple<FSharpList<Interfaces.Node>, IEnumerable<Lexer.Token>>
              Perform(Lexer.BlockToken __p1, Interfaces.IParser __p2,
                   IEnumerable<Lexer.Token> __p3)

again - filters are easy in c# - in fact, a majority of the filters that come with it are written in c#. tags are easy in f#, but a bit messier in c#

in terms of limitations, there aren't any known ones, not that i'm aware of.

full disclosure - i'm one of the ndjango authors.

kolosy
Hmm, the thought of having to learn F# is a tiny bit daunting, but only in the scope of only needing it to build tags. Regardless, it all sounds a lot better than using the standard template system.
Soviut
like you said - the scope of needing f# should be limited to tags, and the ndjango-dev mailing list should be able to help out if you get stuck.
kolosy