I load my stylesheets and js files in <head>
for performance reasons.
My site has multiple components and each template wants to its own extra header files in inside <% yield(:head)
.
I tested <% content_for :head do %>
.. but then I realize it actually overwrites rather than append to a particular section.
What do you guys use?
content_for
actually appends by default. From the documentation, if you were to do...
<% content_for :navigation do %>
<li><%= link_to 'Home', :action => 'index' %></li>
<% end %>
<%# Add some other content, or use a different template: %>
<% content_for :navigation do %>
<li><%= link_to 'Login', :action => 'login' %></li>
<% end %>
If you used...
<ul><%= content_for :navigation %></ul>
It would output...
<ul>
<li><a href="/">Home</a></li>
<li><a href="/login">Login</a></li>
</ul>
Just tested this locally on a rails 3.1.0 app to make sure this is still the case and it does this fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With