4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Sinatraでサブタイトルを付ける

Last updated at Posted at 2016-03-29

たとえばQiitaだったら[記事名] - Qiitaのような[サブタイトル名] -(か|) [サイト名]の形のタイトルをよく見ます。
それを実装するしかたがハマったので書いておきます。

app.rb
get '/' do
    @subtitle = "サブタイトル"
    erb :index
end
layout.erb
<html>
<head>
    <title><%= @subtitle && @subtitle + " - " %>サイト名<title>

つづく…

これで「サブタイトル - サイト名」というタイトルになります
また、サブタイトルを設定しない場合は単に「サイト名」というタイトルになります

Ruby自体が初めて一週間で、Qiitaも初投稿なのでどしどしアドバイスください

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?