Template variables in content?

Hi. I’m trying Hugo out for the first time and have what I suspect might be a simple question. Is it possible to include template variables in a content document? Here’s an example where I’m following the Quick Start guide and then adding {{ .Title }} to my-first-post.md. What I get in the public directory is literally {{ .Title }}, rather than the actual title (“My First Post”). Apologies if I’ve missed something simple.


[is@kev]~$ hugo new site quickstart
Congratulations! Your new Hugo site is created in /Users/is/quickstart.

Just a few more steps and you're ready to go:

1. Download a theme into the same-named folder.
   Choose a theme from https://themes.gohugo.io/, or
   create your own with the "hugo new theme <THEMENAME>" command.
2. Perhaps you want to add some content. You can add single files
   with "hugo new <SECTIONNAME>/<FILENAME>.<FORMAT>".
3. Start the built-in live server via "hugo server".

Visit https://gohugo.io/ for quickstart guide and full documentation.
[is@kev]~$ cd quickstart
[is@kev]~/quickstart$ git init
Initialized empty Git repository in /Users/is/quickstart/.git/
[is@kev]~/quickstart$ git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
Cloning into '/Users/is/quickstart/themes/ananke'...
remote: Counting objects: 850, done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 850 (delta 10), reused 21 (delta 9), pack-reused 823
Receiving objects: 100% (850/850), 2.38 MiB | 1.47 MiB/s, done.
Resolving deltas: 100% (431/431), done.
[is@kev]~/quickstart$ echo 'theme = "ananke"' >> config.toml
[is@kev]~/quickstart$ hugo new posts/my-first-post.md
/Users/is/quickstart/content/posts/my-first-post.md created
[is@kev]~/quickstart$ echo '{{ .Title }}' >> content/posts/my-first-post.md
[is@kev]~/quickstart$ hugo -D
Started building sites ...

Built site for language en:
1 of 1 draft rendered
0 future content
0 expired content
1 regular pages created
8 other pages created
0 non-page files copied
1 paginator pages created
0 tags created
0 categories created
total in 12 ms
[is@kev]~/quickstart$ grep -r '{{' public
Binary file public/images/gohugo-default-sample-hero-image.jpg matches
public/index.html:          {{ .Title }}
public/index.xml:      <description>{{ .Title }}</description>
public/posts/index.html:      {{ .Title }}
public/posts/index.xml:      <description>{{ .Title }}</description>
public/posts/my-first-post/index.html:<meta property="og:description" content="{{ .Title }}" />
public/posts/my-first-post/index.html:<meta itemprop="description" content="{{ .Title }}">
public/posts/my-first-post/index.html:<meta name="twitter:description" content="{{ .Title }}"/>
public/posts/my-first-post/index.html:        <p>{{ .Title }}</p>

P.S. Ooops, editing to add one other bit of info:

[is@kev]~/quickstart$ hugo version
Hugo Static Site Generator v0.29 darwin/amd64 BuildDate: 2017-10-07T00:33:35+01:00

Have a look at shortcodes.

1 Like

Aaargh, I knew it’d be something simple. Thanks very much.