New variables in Posts


There is some way to add costum variables to the front matter of a post? I want to have a variable named “main-image” to use in posts.

I tried to put it into the post like this:

type: post
author:         "Henrique Dias"
title:             "Apresentação"
date:            2014-07-12 14:05:48+00:00
main-image:     "images/apresentacao.jpg"
description: "Uma pequena apresentação sobre o blog e sobre o que quero fazer com ele. Quem sou eu? Que escreverei neste blog? Saberás tudo ao ler!"

And then I would like to access it via .main-image or something like that. Is it possible right now?

Sure. You can use it like:


{{with .Params.main-image}}
// You can now access it through {{.}}

or more explicitly:

{{if isset .Params "main-image"}}
{{ $mainImg := index  Params "main-image"}}
// Use $mainImg here.

Thank you =D

Hmmm… It doesn’t work. It says that function .Params is not defined.

Oops… It actually works… Ahah thanks =D


I think the correct code in single.html should be

{{ with .main-image}}
// Use {{.}} to access main-image here.

instead of :

{{with .Params.main-image}}
// You can now access it through {{.}}

Let me know which code-snippet worked.

Hi! I’m not using HUGO right now and I think I’m not going to use it very
soon. If I use it, I will try this and answer you. Sorry :frowning: