Hugo not reading data from the config file

Hello. I’m a beginner at coding websites and I stumbled across this problem. In my code, I’m trying to make a basic footer using partials. The part that doesn’t seem to work looks like this:

<footer>
     &copy;{{ dateFormat "2006" now }} {{ .Site.Title }}
</footer>

The date part works perfectly, however the {{ .Site.Title }} doesn’t seem to work and outputs nothing when rendered via the hugo server command. The title is defined in the config file. Where is the problem?

{{ .Site.Title }} and your usage looks correct. Any chance you have a link to a repo?

I think you could just do {{ now.Year }} for the copyright.

Edit: Docs say {{ now.Format "2006"}} so maybe now.Year isn’t good advice on my part.

I don’t have a repo yet, sorry. I think that the problem is with how the partials work. I used the exact set of commands in the layout file in the “_default” folder and the command works normally. It’s so weird though. Since I am learning how to use hugo and how to code, I actually almost copied word for word the lines you see in the post from a guy on youtube, and it worked in his case! It doesn’t make much sense to me.

I can copy and paste your snippet into my footer.html partial and it works fine.

My assumption would be that your partial or template structure may be incorrect. That part is hard to say without being able to see your entire hugo project.

If I have my footer content in /layouts/partials/footer.html then I call it /layouts/_default/baseof.html with:

<!DOCTYPE html>
<html lang="{{ .Site.LanguageCode }}">
<head>
    {{- partial "head.html" . }}
</head>
<body>
<div class="page">
    <header>
        {{ partial "header.html" . }}
    </header>
    <nav>
        {{ partial "navigation.html" . }}
    </nav>
    <main>
        {{ block "main" . }}{{ end }}
    </main>
    <footer>
        {{ partial "footer.html" . }}
    </footer>
</div>
</body>
</html>

I’ve got it set up exactly like you described, it still doesn’t work. I discussed this with my friend a moment ago, who has some programming background, and he also doesn’t see, where the problem is. I’m so confused.

I would recommend getting a free github account and push your project up to it so you can share the code for assistance.

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

See Requesting Help.

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.

Hey,
sorry for being non responsive, it’s the time zones. I feel very stupid right now. The problem was that I haven’t included “THE DOT” in my layouts template after the partial command. I am so sorry for bothering you all and thank you very much for you help. I will make sure that next time, when I have any problems, I will put my code on GitHub. Thank you so much though.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.