Ticket #486 (closed enhancement: duplicate)

Opened 10 months ago

Last modified 10 months ago

Specify layout on a per controller, per request basis

Reported by: mir..@digitalhobbit.com Assigned to:
Priority: medium Milestone: The Future
Component: Merb Keywords: layout,controller,request
Cc:

Description

Currently, layouts can be specified as a parameter to the render() method. It is also possible to statically specify the layout for a particular controller by setting the _layout variable (see also http://merb.devjavu.com/ticket/448). However, there does not seem to be a way to declare a method that determines the layout on a per-request basis.

For example, in Rails it is possible to write code like this:

class FooController < ApplicationController
  layout :determine_layout

  private

  def determine_layout
    if wap? ? 'mobile' : 'browser'
  end
end

This behavior is critical in any application that targets multiple clients, such as mobile or facebook applications.

Using a before filter and setting the _layout variable changes the layout statically rather than for the current request only, so this is not a option.

Ideally, the layout method should be smart enough to accept a string (which is interpreted as the name of the layout to use for this controller) or a symbol (which is interpreted as a method name, as in the example above).

Change History

02/11/08 13:49:22 changed by shayarne..@gmail.com

  • status changed from new to closed.
  • resolution set to duplicate.