Rails check if yield :area is defined in content_for

后端 未结 6 1220
我寻月下人不归
我寻月下人不归 2020-12-22 22:23

I want to do a conditional rendering at the layout level based on the actual template has defined content_for(:an__area), any idea how to get this done?

6条回答
  •  一生所求
    2020-12-22 22:42

    I'm not sure of the performance implications of calling yield twice, but this will do regardless of the internal implementation of yield (@content_for_xyz is deprecated) and without any extra code or helper methods:

    <% if yield :sidebar %>
      
    <% end %>
    

提交回复
热议问题