點燈坊

失くすものさえない今が強くなるチャンスよ

Using .Content to Access Markdown Content

Sam Xiao's Avatar 2022-01-17

We can use .Content page variable to access Markdown content.

Version

Hugo 0.91

Page

content000

The page displays content from Markdown.

Markdown

content/_index.md

---
title: My Blog
description: Hello World
subtitle: Page Subtitle
---
## Overview

![home](home.jpg)

This is my first blog.

Line 6

## Overview

![home](home.jpg)

This is my first blog.

The content is written by Markdown.

Layout

layouts/index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="alpine.js" defer></script>
    <link rel="stylesheet" href="output.css" />
  </head>
  <body>
    {{ .Content }}
  </body>
</html>

Line 10

{{ .Content }}
  • .Content : default page variable to access Markdown content

Conclusion

  • Hugo automatically runs .Content through the Markdown parser and provides a string to place directly in the document

Reference

Hugo, Page Variables