# \[SOLVED\] How to Access Front Matter Within Markdown

**URL:** <https://discourse.gohugo.io/t/solved-how-to-access-front-matter-within-markdown/11197>\
**Category:** support\
**Created:** [March 25, 2018, 1:56pm UTC](https://discourse.gohugo.io/t/solved-how-to-access-front-matter-within-markdown/11197 "2018-03-25T13:56:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![xaprb](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/xaprb/32/290_2.png) [@xaprb](https://discourse.gohugo.io/u/xaprb)\
**Post date:** [March 25, 2018, 1:56pm UTC](https://discourse.gohugo.io/t/solved-how-to-access-front-matter-within-markdown/11197/1 "2018-03-25T13:56:37Z")

</div>

Is it possible to include variables from the front matter within the markdown content? Example:

```
---
title: My Blog Post
---
Hello world, this is a post titled {{ .Page.Title }}

```

If I can do this, it’ll help me avoid redundancy, for example, embedding an image thumbnail into the single post’s rendered content and also making a preview of the image thumbnail in the snippets I’m building for the list view. In general I’d like to “parameterize” my content quite a bit more if possible, so I’d use this in a lot of ways.

One possibility seems to be writing a shortcode. Is that the right answer?

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [March 25, 2018, 2:00pm UTC](https://discourse.gohugo.io/t/solved-how-to-access-front-matter-within-markdown/11197/2 "2018-03-25T14:00:59Z")

</div>

> [@xaprb](#):
>
> One possibility seems to be writing a shortcode. Is that the right answer?

I would do it that way; just call the `.Param` function in there. i.e. `.Param "foo"` instead of `.Params.foo`.

---

<div class="post-metadata">

**Author:** ![xaprb](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/xaprb/32/290_2.png) [@xaprb](https://discourse.gohugo.io/u/xaprb)\
**Post date:** [March 25, 2018, 2:20pm UTC](https://discourse.gohugo.io/t/solved-how-to-access-front-matter-within-markdown/11197/3 "2018-03-25T14:20:18Z")

</div>

Thanks for replying. Here’s what I’m trying: I created layouts/shortcodes/param.html with the following contents:

```
{{ with .Get 0 }}{{ .Param . }}{{ end }}

```

And then in my content file,

```
---
thumbnail: thumb.jpg
---
{{< param thumbnail >}}

```

When I run Hugo, it prints the following output:

template: shortcodes/param.html:1:20: executing “shortcodes/param.html” at \<.Param\>: can’t evaluate field Param in type string

I’m not sure what that means. The thumbnail isn’t being output into my rendered content file.

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [March 25, 2018, 2:47pm UTC](https://discourse.gohugo.io/t/solved-how-to-access-front-matter-within-markdown/11197/4 "2018-03-25T14:47:31Z")

</div>

Hmm, admittedly I haven’t tried that… so not sure if it will work… try `$.Param` instead (put that dollar sign). The $ will set a context where that Param should be called.

---

<div class="post-metadata">

**Author:** ![regis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/regis/32/4958_2.png) [@regis](https://discourse.gohugo.io/u/regis)\
**Post date:** [March 25, 2018, 6:24pm UTC](https://discourse.gohugo.io/t/solved-how-to-access-front-matter-within-markdown/11197/5 "2018-03-25T18:24:13Z")

</div>

Try

```auto
{{ with .Get 0 }}{{ $.Page.Param . }}{{ end }}

```

or

```auto
{{ with .Get 0 }}{{ index $.Page.Params . }}{{ end }}

```

With the later, you may get an error if the param has not been set in the Front Matter.

---

<div class="post-metadata">

**Author:** ![xaprb](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/xaprb/32/290_2.png) [@xaprb](https://discourse.gohugo.io/u/xaprb)\
**Post date:** [March 25, 2018, 7:30pm UTC](https://discourse.gohugo.io/t/solved-how-to-access-front-matter-within-markdown/11197/6 "2018-03-25T19:30:21Z")

</div>

This works for me:

```
{{ with .Get 0 }}{{ $.Page.Param . }}{{ end }}

```

I didn’t try the second option. But this works for all parameters I tried, including built-in ones like description and random stuff I just put into the front matter. It also works for parameters that don’t exist in the front matter. Thanks to all who helped!

---

<div class="post-metadata">

**Author:** ![Rick](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rick/32/2469_2.png) [@Rick](https://discourse.gohugo.io/u/Rick)\
**Post date:** [June 23, 2018, 6:56am UTC](https://discourse.gohugo.io/t/solved-how-to-access-front-matter-within-markdown/11197/7 "2018-06-23T06:56:16Z")

</div>

Brilliant, but have any of you tried using it with a date parameter? And if so, how did you format the date?

---

<div class="post-metadata">

**Author:** ![regis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/regis/32/4958_2.png) [@regis](https://discourse.gohugo.io/u/regis)\
**Post date:** [June 24, 2018, 12:49pm UTC](https://discourse.gohugo.io/t/solved-how-to-access-front-matter-within-markdown/11197/8 "2018-06-24T12:49:14Z")

</div>

Have you searched for « format date » in the doc?

---

<div class="post-metadata">

**Author:** ![Rick](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rick/32/2469_2.png) [@Rick](https://discourse.gohugo.io/u/Rick)\
**Post date:** [June 26, 2018, 8:23am UTC](https://discourse.gohugo.io/t/solved-how-to-access-front-matter-within-markdown/11197/9 "2018-06-26T08:23:47Z")

</div>

> [@xaprb](#):
>
> Get 0 }}{{ $.Page.Param . }}{{ end }}

Thanks for responding @regis, If the front matter parameter you’re fetching is a date, how would you format that in the markdown?

`{{< param Date.Format "2 jan, 2006" >}}` doesn’t work. Of course, one could create a custom shortcode for dates, but I was wondering if the universal shortcode suggested above would suffice.

---

<div class="post-metadata">

**Author:** ![regis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/regis/32/4958_2.png) [@regis](https://discourse.gohugo.io/u/regis)\
**Post date:** [June 26, 2018, 10:50am UTC](https://discourse.gohugo.io/t/solved-how-to-access-front-matter-within-markdown/11197/10 "2018-06-26T10:50:54Z")

</div>

I did not understand you needed to change the date format directly from your markdown.  
But in this case why not create your own Shortcode ?

---

<div class="post-metadata">

**Author:** ![Rick](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rick/32/2469_2.png) [@Rick](https://discourse.gohugo.io/u/Rick)\
**Post date:** [June 26, 2018, 11:16am UTC](https://discourse.gohugo.io/t/solved-how-to-access-front-matter-within-markdown/11197/11 "2018-06-26T11:16:13Z")

</div>

Yep, sorry for the confusion.
