# Django-like nested templates with Rails layouts

**URL:** <https://www.ruby-forum.com/t/django-like-nested-templates-with-rails-layouts/142284>\
**Category:** Rails\
**Created:** [July 6, 2008, 1:53am UTC](https://www.ruby-forum.com/t/django-like-nested-templates-with-rails-layouts/142284 "2008-07-06T01:53:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JonSidnell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/4bbf92/32.png) [@JonSidnell](https://www.ruby-forum.com/u/JonSidnell)\
**Post date:** [July 6, 2008, 1:53am UTC](https://www.ruby-forum.com/t/django-like-nested-templates-with-rails-layouts/142284/1 "2008-07-06T01:53:31Z")

</div>

Hi everyone

I’ve been briefly flirting with Django, and have decided that I’m  
going to stick with Ruby on Rails for the time being. The only thing I  
think I’m going to miss is Django’s implementation of nested  
templates.

Thinking my way through it now, the closest I can think of would be to  
bundle the common content off into a load of partials (say “header”,  
“menu”, “footer” and so on). While this is better in that changing  
things within the partials would be accomplished in just one place,  
but it would still result in a bunch of files with very similar  
content, that would all need amending should I want to add an extra  
partial to each layout.

Has anyone got any strategies or ideas for accomplishing gives you?

Thanks  
Jon

---

<div class="post-metadata">

**Author:** ![JonSidnell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/4bbf92/32.png) [@JonSidnell](https://www.ruby-forum.com/u/JonSidnell)\
**Post date:** [July 6, 2008, 11:04am UTC](https://www.ruby-forum.com/t/django-like-nested-templates-with-rails-layouts/142284/2 "2008-07-06T11:04:16Z")

</div>

I don’t know, what exactly “nested templates” in Django do…

But you can nest partials into each other as deep as you like, you can  
even nest one in itself recursively.  
\<%= render :template =\> “another\_partial” %\>  
or you can use the content\_for thingy in a layout (eg for the menu  
part)

say:  
\<%= yield :some\_menu %\>

and then in the partial to be rendered:  
\<% content\_for :some\_menu %\>  
… some html here…  
…or another render :partial =\> :whatever\_menu…  
\<% end %\>

There are so many ways to define & render partials, hand in some  
data to them with :locals, :object and so on, that I can’t imagine  
much  
you ould not do with them.

---

<div class="post-metadata">

**Author:** ![JonSidnell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/4bbf92/32.png) [@JonSidnell](https://www.ruby-forum.com/u/JonSidnell)\
**Post date:** [July 6, 2008, 1:29pm UTC](https://www.ruby-forum.com/t/django-like-nested-templates-with-rails-layouts/142284/3 "2008-07-06T13:29:55Z")

</div>

If you want to nest layouts within layouts (which it doesn’t appear  
you want to do, but I think it’s worth mentioning anyway), you can use  
the nested\_layouts plugin.
