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).