I feel the view system is lacking simple a system to just create a “sub layout”. Intuitively its pretty simple, but the guide for it is a bit rough i find: Layouts and Rendering in Rails — Ruby on Rails Guides
I mean, lets say i want an “administration” layout. It would be like application, but have an extra menu within the yield of the “application” layout.
In my mind, this is what I would want to do:
<%= extends :application do %> # Put my menu here = yield <% end %>
The guide currently suggests using
content_for?(:content) ? yield(:content) : yield in the application layout, and then using content_for and
<%= render template: "layouts/application" %> in the sub layout. But the
extends approach seems much more intuitive to me.
The big advantage of
extends above is that parent layout wouldn’t have to care / be modified.
A gem exists which does this. It seems to still work in Rails 6, but it hasn’t been changed since 2016. The code for the feature is 7 lines: nestive/layout_helper.rb at master · rwz/nestive · GitHub
With this feature, think of how simple the guide for nested layouts would be. Layouts and Rendering in Rails — Ruby on Rails Guides It would should an example of
extend and then mention that if modifications to the content of the application layout are needed, they should look at the
Any thoughts? I’d be happy to look into making a PR if feedback is positive