Display name
Display name

Reputation: 4501

blogdown `title` won't display on rendered `_index.html`

I created an _index.Rmd file in my blogdown /*/content/ directory and the body of the _index.Rmd file looks like this:

---
title: "Home"
date: "2016-05-05T21:48:51-07:00"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

Welcome to the home page of this blogdown site.

I would expect to see a "Home" title heading but nothing appears. I presume this is an intentional design choice. I can understand why, but in my case I want the title that I specify in the YAML to showup on the rendered _index.html file. How do I achieve this goal?

enter image description here

Upvotes: 1

Views: 221

Answers (1)

Jozef
Jozef

Reputation: 2747

This is because the index (main) page has special treatment with this theme. How you can change this is go to themes/(yourtheme)/layouts/index.html. It would look something like:

{{ partial "header.html" . }}

<main class="content">

  <div class="list">
     {{ range (.Paginate ((where .Data.Pages "Type" "post").GroupByDate "2006")).PageGroups }}    
  <h2 class="list-title">{{ .Key }}</h2>
    {{ range .Pages }}

    {{ partial "list-item.html" . }}

    {{ end }}
    {{ end }}
  </div>  

  {{ partial "pagination.html" . }}

</main>

{{ partial "footer.html" . }}

Now you can edit this file to add the desired title in many ways, for example if you want the same style as a post title would have you could add between the <main class="content"> and <div class="list>:

<h1 class="article-title">Home</h1>

If you want to source the title from the .Rmd file, you would do:

<h1 class="article-title">{{ .Title }}</h1>

Now after rebuilding the site the title will appear on the homepage.

Upvotes: 2

Related Questions