views:

93

answers:

1

Hi, my question is very simple. I will ask it first incase the answer is obvious, and then I will explain what I mean, incase it's not obvious.

Is it considered ok to make your main 'yield' call from a partial instead of doing it directly from your layout.html.haml file? Does doing so result in any kind of perforance loss.


Explanation...

I have one layout file called application.html.haml.

I want my main content to take up the full page width unless there is a sidebar present for that page.

If there is a sidebar then I want the main content to take up 66% page width and the sidebar to use up the remaining space.

I have the following in my layout:

#content
  - if show_sidebar?    
    #main
      = yield
    #sidebar
      = yield(:sidebar)
  -else
    = yield

The content div is 100% page width. If no sidebar is present then the 'yield' results go into this div. If there is a sidebar then the main yield goes into a div called #main which is 66% page width.

Great, this works fine.

Now, in order to keep my main view tidy, I have refactored my code a little so that it now looks like this:

#content
  - if show_sidebar?
    - render :partial => 'main_with_sidebar'
  -else
    = yield

And then in the partial _main_with_sidebar.html.haml I have this:

    #main
      = yield
    #sidebar
      = yield(:sidebar)

So everything is the same, except for the fact that whenever there is a sidebar present, the main yield is called from a partial.

And so my question regards whether or not this is considered best practice. Or should I just stick to having a slightly messier application.html.haml file and get rid of the partial? It doesn't seem to cause any problems but I'd like to know if I'm doing something wrong before I go too far with it.

Yes it might seem dumb to some of you guys, but I'm a designer rather than a dev and this sort of thing is new to me....

+1  A: 

I would simply create a new layout for the "layout with sidebar"

views/layouts/application.html.haml
views/layouts/sidebar.html.haml
knoopx
thanks. that is exactly how I used to do it, and to be honest, I think it's how I'm going to have to continue doing it. I think it's easier and since I'm working with other designers, it might suit them more if it's done that way.Thanks. Can't believe how long I've spent deliberating over this!
stephenmurdoch