Accessing .GitInfo in templates


I’m wanting to use some of the components of .GitInfo in my templates.

I have got it working for layouts/index.html. Inserting {{ .GitInfo }} into that template results in the Git information being dumped into the home page of the site. So far, so good. This confirms that the configuration and system requirements are all in place.

However, I actually want to use .GitInfo in my layouts/_default/single.html template. However, now it simply returns nil in the rendered document. Based on this I have also tried .Page.GitInfo but got the same result.

Is .GitInfo accessible from the templates in layouts/_default?

Thanks, Andrew.

Yes, it is.

You are more likely to receive a prompt and accurate response if you post a link to the public repository for your project.


Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.