Yielding content_for with a block of default content

前端 未结 1 716
伪装坚强ぢ
伪装坚强ぢ 2021-01-05 17:58

Our Rails projects make heavy use of content_for. However, we quite often need to render default content if nothing is defined using content_for. F

相关标签:
1条回答
  • 2021-01-05 18:46

    This can be done entirely in the view using the content_for? method.

    <% if content_for?(:sidebar_content) %>
      <%= yield(:sidebar_content) %>
    <% else %>
      <ul id="sidebar">
        <li>Some default content</li>
      </ul>
    <% end %>
    
    0 讨论(0)
提交回复
热议问题