Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using different layouts for an entire controller

I'm having problems with something that should be simple.

I have two use cases...

  • The user is the site directly
  • The user is using an iframe from another site

I want to do the same thing in either case except I don't want to use the layout for my website in the case it's the iframe so I have a "plain" layout

layout "plain"

How can I dynamically assign the layout depending on the case..

ie params[:iframe] == true etc.

Nothing I do seems to work.

like image 438
holden Avatar asked Nov 03 '10 20:11

holden


People also ask

Can we have multiple layouts in MVC?

Yes, we can use multiple Layout in ASP.Net MVC application. By default, Visual Studio adds a Layout page in a shared folder which can be used by other View pages if required. In some cases, we can have the requirement to use multiple shared layout pages in MVC application.

Can we have multiple _ViewStart in MVC?

We can also create multiple _ViewStart. cshtml pages. The file execution is dependent upon the location of the file within the folder hierarchy and the view being rendered. The MVC Runtime will first execute the code of the _ViewStart.


1 Answers

try this

layout :layout_by_resource

def layout_by_resource
  if params[:iframe] == true
    'plain'
   else
    "your-main-layout"
  end
end
like image 166
Jonathan Avatar answered Oct 10 '22 09:10

Jonathan