Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documents the body_class parameter #1541

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions userguide/content/en/docs/adding-content/lookandfeel.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,35 @@ Both `head.html` and `scripts.html` are then used to build Docsy's [base page la
</html>
```

## Adding custom class to the body element

By default, Docsy adds the `td-{{ .Kind }}` class, where the kind is the kind of the page, like section, blog, and so on. For example:
fekete-robert marked this conversation as resolved.
Show resolved Hide resolved

```html
<body class="td-section">
```

Sometimes it's useful to assign custom classes to a page, or to an entire section, for example, to apply custom styling. To do so, add the `body_class` parameter to the frontmatter of your page. The value of the parameter will be then added to the class attribute of your page's body element.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please line-wrap all long paragraphs in this delta.

Also:

  • "will be then" --> "will then be"


To add the classes `myclass` and `anotherclass`, add the following line to the frontmatter of the page:

{{< tabpane persistLang=false >}}
{{< tab header="Configuration file:" disabled=true />}}
{{< tab header="hugo.toml" lang="toml" >}}
body_class = "myclass anotherclass"
{{< /tab >}}
{{< tab header="hugo.yaml" lang="yaml" >}}
body_class : myclass anotherclass
{{< /tab >}}
{{< tab header="hugo.json" lang="json" >}}
"body_class" : "myclass anotherclass"
{{< /tab >}}
{{< /tabpane >}}

The page's opening body tag will look like this (assuming it is a section page):

```html
<body class="td-section myclass anotherclass">
```

To apply the custom class to every page of a section or a directory, use the [Front Matter Cascade](https://gohugo.io/content-management/front-matter/#front-matter-cascade) feature of Hugo in your configuration file, or in the frontmatter of the highest-level page you want to modify.