Tech Talk

Bytefull of Tech Talk (http://tech.bytefull.com)

Django Templates for Rails ?

I know this is perverse but I wish the Django Template language was available for Rails.

Beat this:

{%extends ‘base’%} {%block leftnav} a link {%endblock%} {% block content %} this is the content {% endblock %} {% block footer%} another link{%endblock%}

If you leave out a ‘block’ it will pick up the default content from its parent ‘base’ template. Everything between the blocks is rendered as per the parent template. In short, you can ‘extend’ the bits you want, or just render the parent template. A more detailed explanation is available here.

Compared to that, Rails lacks nested layouts. You can only have one level of inheritance: application-wide. There’s a nested_layout plugin that provides the required functionality, but it isn’t as elegant as the above Django example.

I’ve been looking at liquid, which looks similar to Django’s Templates, but it doesn’t seem to be documented well. I’m now looking at HAML, which seems promising, but I may just be too deep into the project to change now. I may have to survive on partials !

June 6th, 2007 | ahsan | Other

3 Responses to “Django Templates for Rails ?”

  1. Adrian Holovaty Says:

    Dude, just use Django.

  2. Ahsan A. Says:

    Adrian, I’ve tried Django, and I really like it. I think I like everything about django from the templating language to the URL pattern matching to the models to the great Django book.

    The only thing that dissuaded me from using Django is the lack of a 1.0 release. Yes, I’ve been told the svn version is ’stable’, but the newforms library wasn’t complete the last time I checked !

    The irrational part of my argument _for_ rails, is my love for ruby, the language…

  3. Matt Westcott Says:

    I was after the same thing, so I’ve made a (not too pretty) attempt at implementing it:
    http://matt.west.co.tt/ruby/djerb/

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.