Created
February 18, 2016 08:01
-
-
Save jamesmartin/51bcaf4b70cb0653cfbb to your computer and use it in GitHub Desktop.
Custom title tag for each page of a Sinatra app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| before do | |
| # We set this @title instance variable to a default value, so that if any of our pages *don't* want a custom title, something will appear in the <title> tag. | |
| @title = "My Default Title" | |
| end | |
| # For this route we set a custom title for the page using the @title instance variable | |
| get '/some/path' do | |
| @title = "Whatever" | |
| # render &etc... | |
| end | |
| # This route has no @title instance variable set, so the layout.erb will use the "My Default Title" value | |
| get '/some/other/path' do | |
| # render &etc... | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <title> | |
| <%= @title %> | |
| </title> | |
| <body> | |
| ... &etc. | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment