# How can a layout check if disableKinds includes "sitemap"?

**URL:** <https://discourse.gohugo.io/t/how-can-a-layout-check-if-disablekinds-includes-sitemap/38097>\
**Category:** support\
**Created:** [April 8, 2022, 2:01am UTC](https://discourse.gohugo.io/t/how-can-a-layout-check-if-disablekinds-includes-sitemap/38097 "2022-04-08T02:01:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cshoredaniel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/cshoredaniel/32/19684_2.png) [@cshoredaniel](https://discourse.gohugo.io/u/cshoredaniel)\
**Post date:** [April 8, 2022, 2:01am UTC](https://discourse.gohugo.io/t/how-can-a-layout-check-if-disablekinds-includes-sitemap/38097/1 "2022-04-08T02:01:02Z")

</div>

In `layouts/robots.txt` I have:

```auto
{{- $defaultSitemap := site.Home.Sitemap.Filename | absURL -}}

```

and later

```auto
{{ with $defaultSitemap }}Sitemap: {{ . | absURL }}{{ end -}}

```

But (with `hugo server -b http://localhost:1313/` I always get `Sitemap: http://localhost:1313/sitemap.xml` in the output, even if in `config.toml` I have

```nohighlight
disableKinds = ["sitemap","RSS"]

```

before any maps (like `[params]`). Is there a way for the `robots.txt` partial to detect if the sitemap is in fact generated for this site?

I’ve tried looking at `.OutputFormats.Get "sitemap"` and `.AlternativeOutputFormats`, but I haven’t found anything that will let me omit specifying a sitemap when there isn’t one.

If one of what I described ‘should work’ I’ll do up a test case, but based on going blind reading the docs, I can’t find anything that looks like it would do what I want, so I wanted ask if it is even possible.

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [April 8, 2022, 2:56am UTC](https://discourse.gohugo.io/t/how-can-a-layout-check-if-disablekinds-includes-sitemap/38097/2 "2022-04-08T02:56:00Z")

</div>

This works:

```nohighlight
disableKinds = ["sitemap"]
[sitemap]
  filename = ''

```

With above in `config.toml` and this in a template file:

```nohighlight
{{ with site.Home.Sitemap.Filename }}
    sitemap present
{{ else }}
    no sitemap
{{ end }}

```

I get “no sitemap”.

---

<div class="post-metadata">

**Author:** ![cshoredaniel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/cshoredaniel/32/19684_2.png) [@cshoredaniel](https://discourse.gohugo.io/u/cshoredaniel)\
**Post date:** [April 8, 2022, 3:00am UTC](https://discourse.gohugo.io/t/how-can-a-layout-check-if-disablekinds-includes-sitemap/38097/3 "2022-04-08T03:00:54Z")

</div>

Thank you! As a workaround that will get the job done in a better way than introducing a new param. I’d prefer not having to do a work around, but it’s not something I think worth an ‘feature request’ and then bep (most likely, if anyone) working on it.

I didn’t think of that, so thanks again 🎉

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [April 8, 2022, 3:21am UTC](https://discourse.gohugo.io/t/how-can-a-layout-check-if-disablekinds-includes-sitemap/38097/4 "2022-04-08T03:21:35Z")

</div>

```auto
site.SitemapAbsURL

```

Saves some typing…

---

<div class="post-metadata">

**Author:** ![cshoredaniel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/cshoredaniel/32/19684_2.png) [@cshoredaniel](https://discourse.gohugo.io/u/cshoredaniel)\
**Post date:** [April 8, 2022, 3:40am UTC](https://discourse.gohugo.io/t/how-can-a-layout-check-if-disablekinds-includes-sitemap/38097/5 "2022-04-08T03:40:29Z")

</div>

@jmooring That’ll be nice for some uses - guess the docs haven’t caught up to the addition of that.

Unfortunately with @kaushalmodi’s workaround and `baseURL` set (but no `<base href=...>`) this returns the value of `baseURL` which means using an `if` instead of `with`. Not a big deal, but is less helpful than intended 🫤 .

Ah well… I’m just happy I don’t have to introduce a new param, and I am grateful for the thought.

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [April 10, 2022, 3:40am UTC](https://discourse.gohugo.io/t/how-can-a-layout-check-if-disablekinds-includes-sitemap/38097/6 "2022-04-10T03:40:39Z")

</div>

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