Getting the actual page name for a footer?


I’d like to use a mailto link in .../content/ and I’d like the link to contain the name of the actual page being shown (as opposed to the footer file). How can I get this information?



You mean the page’s title as ‘name of actual page’? You get that with the .Title page variable.

But I don’t really follow. Can you perhaps give an example of how ‘name of actual page’ looks like? Because I suppose you already thought of .Title, so your use case is probably more complex and detailed than your question suggests.


OK, here’s an example. The title is “Bookshare” and the URL is “http://localhost:1313/at_cat/offering/computer/service/content/bookshare/”.
The subject for the mailto should let me know where the user was, eg:

FWIW, when I put Title: {{ .Title }} in .../content/, the footer displays: Title: {{ .Title }}, so I’m clearly pretty clueless…



Ah I see. This is not something that Hugo can do. Because Hugo is a static site generator, it can ‘only’ generate HTML files. But Hugo can’t track or see which path people took to arrive at a certain page.

Luckily, JavaScript can with document.referrer.

That’s right, .Title won’t do anything when you place them in content files. Such variables have to be put in the Hugo templates that render your theme or in a shortcode. Else Hugo can’t run them.


Although document.referrer isn’t quite right for my use case (it returns the URL of the referring page), window.location.href works nicely. Thanks!

Still, it seems to me that Hugo has to know the expected URL (or at least the pathname) of the current page while it’s processing Isn’t this available?



Not a partial called footer.html? If it’s a partial, you can definitely get the title parameter…


Yeah, you can do that. @Jura was thinking of something more like analytics, where you can get referrer info from headers or whatever. But if you just want something like this:

<a href="">Contact Rich</a>

To generate that, you do something like:

<a href="{{ .Title }}">Contact Rich</a>

The partial @rdwatters mentions is where that will likely go, and you may need to run it through safeURL to get it working correctly. Make sure to check the docs on partials. :slight_smile:


To close things out, here is the approach I’m currently using in

Please feel free to <span id="email_link">foo</span>
comments, inquiries, suggestions, etc!

<script type="text/javascript">
  document.getElementById("email_link").innerHTML =
    '<a href="' +
    window.location.href + '">email</a>';