I'm using the content_for
helper to e.g. set a page title in my rails 3 app. One snippet of erb I'm still using in some places is
<title><%= yield(:title) -></title>
or written in HAML would be
%title= yield(:title)
Now I have a HAML template setting this title:
- content_for :title do
My awesome title
- content_for :something_else do
which results in
<title>My awesome title
</title>
How can I avoid the newline before </title>
? It's definitely set in :title
– adding +"X"
will put the X
behind the newline.
I already tried
-< content_for :title do
-> content_for :title do
but either one leads to an error. Whitespace removal seems to be not working with ruby evaluation.
In your layout template, do:
%title= content_for?(:title) ? "#{yield(:title)}" : "Default Title"
Then in your content templates, do:
= content_for(:title, "Welcome to my home page!")
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