Well, I’ve got a question, that I hope someone can assist with:
After upgrading to v0.21-DEV-9EC00725 today, I now get an error about building the footer for the 404.html template, which I have in layouts. The error is similar to the above, but it did not appear until today:
ERROR 2017/04/11 21:01:38 Error while rendering "404": template: /Users/rcogley/dev/RCC-live/layouts/404.html:28:6: executing "footer" at <partial "footer.html...>: error calling partial: template: partials/footer.html:12:127: executing "partials/footer.html" at <.GitInfo.Abbreviated...>: can't evaluate field AbbreviatedHash in type *gitmap.GitInfo
So, like I did with my root index and section index, I added a markdown file and referenced it in the 404.html, using {{ .Content }}. This time however, it does nothing, and the markdown’s content is not pulled into the template.
I also can’t use:
{{ if and (ne .Kind "taxonomy") (ne .Kind "taxonomyTerm") }}<small class="gray"><em>Updated: {{ .Lastmod }} {{ .GitInfo.AbbreviatedHash }}</em></small>{{ end }}
… because there is no “kind” that matches this error page, I think.
Any workaround for this? I guess I could make a section “error” then add the template and its content for that, and, point to the file using .htaccess. Does Hugo “care” if the 404 is in the root or not?
However, when I try {{ with .GitInfo }} I still get errors in hugo server’s log, re all the types that don’t have that - root index, section index etc. Apparently, it expects the template to be applied to content that actually has a .GitInfo to query in the first place, and chokes if you use it as a general filter.
Hi, I’m puzzled about how to access a GitInfo variable from within a partial included from baseof. It seems like GitInfo is only accessible from within a Page template (not partials or List templates or baseof templates)?
Is there no way to access e.g. {{ .GitInfo.AbbreviatedHash }} from my single.html template, save it in a block, and then reference that block’s value from a partial included by baseof.html (e.g. head.html)? If not, can someone please clarify why?
Yes, enableGitInfo is true in the site config and as a command line flag.
Are you passing the “context” … the dot to the partial?
Yes. I’m not sure why it wasn’t working. The exact flow of Hugo template logic between baseof blocks, themes, partials, _default, index, lists, etc. is still a little tricky for me to get my head around when debugging. The error Hugo kept emitting was:
execute of template failed: template: index.html:8:17:
executing “index.html” at <.GitInfo.AbbreviatedHash>:
can’t evaluate field AbbreviatedHash in type *gitmap.GitInfo
So accessing the GitInfo hash from baseof (on a single.html layout) works now. Question 2 is, why is the GitInfo hash not accessible outside of a single layout (or single’s baseof)? I can’t get the the git SHA for e.g. a list page template (the template file itself, not the content list)?
May be you are getting confused with all the terminology? There’s isn’t a “single’s baseof”. From what I have seen and used, there’s one and only one baseof.html that’s put in _default (and it’s entirely possible that I am wrong).
Do you want to have a look at how I organize the theme in my “bare bones” theme? It’s using single.html, baseof.html, etc.
Thanks! No, I do understand how baseof works, I was referring to the site’s _default/baseof, as in: the content markdown maps to _default/single which overrides blocks defined in _default/baseof which loads some partials, etc.
The question is, why does GitInfo only work for content files versioned in Git and not templates versioned in Git? What if I just want the overall latest SHA of the branch?