SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    976
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Nested layouts and Engines

    I have a main application, does some basic 'core' functions and then everything else is a mountable engine.
    What I would like to do is to enclose the engine layout in the application layout. Each engine might have a different layout but I have a base 'frame' for the entire application.

    Something like this
    application_layout (yields entire layout)
    --> engine_layout (yields engine layout with current_action html)
    -- --> current_action_view (yields current action html)

    I looked at nested layouts on the rails guides site and this seems like it's the answer but it's not working as expected.

    Anyone know if what I'm wanting to do is possible?
    your brain reacts in the same way whether you are
    looking at something or thinking about it...

  2. #2
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,116
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    Rails only allows one layout and a view to work out of the box with one yield block. So I believe an engines layout file will disregard the application layout.
    If you want to nest you need to use content_for blocks and custom template render calls to do what you want.
    http://guides.rubyonrails.org/layout...nested-layouts

    Does that help you?

  3. #3
    SitePoint Guru downtroden's Avatar
    Join Date
    Dec 2004
    Location
    illinois
    Posts
    976
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, thanks.

    I don't agree with calling this 'nested layouts' as it's not using layouts inside of layouts, it's just using content blocks…*doesn't seem the same.
    your brain reacts in the same way whether you are
    looking at something or thinking about it...

  4. #4
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,116
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    You can explicitly call render 'template.blah' to nest views, you are right that overriding content_for blocks is just switching out parts of the layout.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •