Skip to content

Instantly share code, notes, and snippets.

@jamesmartin
Created February 18, 2016 08:01
Show Gist options
  • Select an option

  • Save jamesmartin/51bcaf4b70cb0653cfbb to your computer and use it in GitHub Desktop.

Select an option

Save jamesmartin/51bcaf4b70cb0653cfbb to your computer and use it in GitHub Desktop.
Custom title tag for each page of a Sinatra app
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
<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