Sitemap variables unavailable in robots.txt template

I’m running into an issue where it appears that within the robots.txt template [1] the sitemap variables [2] are not available. I can reproduce this issue with the following steps. First run hugo new example to make a basic site. Then add the following to the config.toml file:

enableRobotsTXT = true

Then create the following file at layouts/robots.txt:

User-agent: *
Sitemap: {{ .Sitemap.Filename }}

If you then run hugo to generate the site, public/robots.txt looks like this:

User-agent: *
Sitemap: 

I could not find documentation or other posts/issues on this behavior. It can be worked around with something like {{ "sitemap.xml" | absURL }} where you hard-code the sitemap name, but I’m wondering if this may be worth filing as a bug.

[1] Robots.txt File | Hugo
[2] Sitemap Variables | Hugo

Sitemap variables are available on .Page. So do something like:

{{ site.Home.Sitemap.Filename }}
7 Likes

That worked, thank you!

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