# Dynamic layout - title for google page rank

**URL:** <https://www.ruby-forum.com/t/dynamic-layout-title-for-google-page-rank/110719>\
**Category:** Rails\
**Created:** [July 30, 2007, 7:45am UTC](https://www.ruby-forum.com/t/dynamic-layout-title-for-google-page-rank/110719 "2007-07-30T07:45:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![minka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b38774/32.png) [@minka](https://www.ruby-forum.com/u/minka)\
**Post date:** [July 30, 2007, 7:45am UTC](https://www.ruby-forum.com/t/dynamic-layout-title-for-google-page-rank/110719/1 "2007-07-30T07:45:49Z")

</div>

Google likes titles to be distinct for every page and they use that  
for page rank. My old layout had the same title for every page. I  
looked up  
dynamic layout in this group and followed the suggestion for  
page specific titles. Now I have a  
‘@title’  
variable in the controllers, I assign it in index and other routines  
like this:  
‘def index  
@title = “something”  
end’  
whatever is the appropriate title for that page and then in the layout  
I have  
‘ \<%= @title =\> ’

This WORKS in the test environment but when I capistrano upload the  
app to the production environment title is ALWAYS blank, an empty  
string.

Any suggestions?  
thanks,

minka  
[http://www.beelucid.com](http://www.beelucid.com)

---

<div class="post-metadata">

**Author:** ![minka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b38774/32.png) [@minka](https://www.ruby-forum.com/u/minka)\
**Post date:** [July 30, 2007, 8:30am UTC](https://www.ruby-forum.com/t/dynamic-layout-title-for-google-page-rank/110719/2 "2007-07-30T08:30:16Z")

</div>

minka wrote:

> end’  
> whatever is the appropriate title for that page and then in the layout  
> I have  
> ‘ \<%= @title =\> ’
> 
> This WORKS in the test environment but when I capistrano upload the  
> app to the production environment title is ALWAYS blank, an empty  
> string.

Ah, there is a much more elegant way of doing this! 🙂

ActionView has a content\_for method, which you can use.

Here is a blog post explaining how it works (with some extra stuff)

[http://blog.imperialdune.com/2007/3/27/dirty-views-clean-them-up](http://blog.imperialdune.com/2007/3/27/dirty-views-clean-them-up)

In a nutshell… in your application layout.

DHH Gossip » \<%= (title = yield :title) ? title : 'Your source for the latest DHH gossip' %\>

Then in your views…

# news.rhtml

\<% content\_for :title do %\>DHH kills Bat Boy!\<% end %\>

When rendered, this will appear in your. As you can see, I also defined  
a default string above.

You can do several content\_for’s in your app (sidebar, navigation,  
breadcrumbs…)

Good luck!

Cheers,  
Robby

–  
Robby R.  
[http://www.robbyonrails.com/](http://www.robbyonrails.com/)

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

---

<div class="post-metadata">

**Author:** ![minka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b38774/32.png) [@minka](https://www.ruby-forum.com/u/minka)\
**Post date:** [July 30, 2007, 8:32am UTC](https://www.ruby-forum.com/t/dynamic-layout-title-for-google-page-rank/110719/3 "2007-07-30T08:32:17Z")

</div>

Robby R. wrote:

> > @title = “something”  
> > Ah, there is a much more elegant way of doing this! 🙂
> 
> DHH Gossip » \<%= (title = yield :title) ? title : 'Your a default string above.
> 
> You can do several content\_for’s in your app (sidebar, navigation,  
> breadcrumbs…)

Also, here is the documentation for content\_for.

[http://api.rubyonrails.com/classes/ActionView/Helpers/CaptureHelper.html#M000638](http://api.rubyonrails.com/classes/ActionView/Helpers/CaptureHelper.html#M000638)

Cheers,  
Robby

–  
Robby R.  
[http://www.robbyonrails.com/](http://www.robbyonrails.com/)

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.
