Ability to set layout on a per-controller basis
Reported by Shay Arnett | February 11th, 2008 @ 11:04 PM | in 0.9
Originally posted on Trac by cvonkleist@gmail.com
Description
I have a bunch of admin controllers in my Merb app that I want to use a different layout from my other controllers. My admin controllers should use the 'admin' layout, and the rest of my controllers should use the 'application' layout.
I can make them use the 'admin' layout by doing this:
class Admin::Users < Application
self._layout = 'admin'
end
And that works, but I think this would be better:
class Admin::Users < Application
layout :admin
end
For now, I've made it work like that by defining the layout method in my Application controller (from which all my other controllers inherit):
class Application < Merb::Controller
def self.layout(name)
self._layout = name.to_s
end
end
Thanks to Yann KLIS on the merb-devel mailing list for showing me how to use self._layout = 'foo'.
Trac Attachments
Trac Comments
01/13/08 12:34:42 changed by lancecarlson@gmail.com
I like the idea, if it doesn't already exist. +1
01/28/08 22:57:46 changed by mirko@digitalhobbit.com
This is a good idea, but I think we need to take it a step further and allow controllers to specify a method that determines the layout on a per-request basis, as in Rails. I just filed a ticket to describe the proposal: http://merb.devjavu.com/ticket/486
Therefore, I am against using the notation you propose to specify a (static) layout:
layout :admin
Instead, the following should be used to specify a static layout:
layout 'admin'
And the following could be used to specify a dynamic layout, based on the request:
layout :determine_layout
private
def determine_layout
if some_condition? ? 'layout1' : 'layout2'
end
This is crucial for any application that targets different clients, such as mobile vs. browser, facebook, or different classes of users.
Comments and changes to this ticket
-
Shay Arnett February 26th, 2008 @ 10:58 PM
doesn't the new layout allow this? also the old self._layout should have worked as well
-
Yehuda Katz (wycats) February 28th, 2008 @ 10:41 PM
- → Milestone changed from to 0.9
- → State changed from new to resolved
The new layout supports this (via _get_layout in RenderMixin).
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
