# Display/ Hide Page

**URL:** <https://discourse.gohugo.io/t/display-hide-page/29793>\
**Category:** support\
**Created:** [December 4, 2020, 7:11am UTC](https://discourse.gohugo.io/t/display-hide-page/29793 "2020-12-04T07:11:22Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Semih\_Ural](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/semih_ural/32/12799_2.png) [@Semih\_Ural](https://discourse.gohugo.io/u/Semih_Ural)\
**Post date:** [December 4, 2020, 7:11am UTC](https://discourse.gohugo.io/t/display-hide-page/29793/1 "2020-12-04T07:11:22Z")

</div>

Hi,

I added a shortcode to website for display/hide complete page according to the params. Actually it works but what I want is completely hide this page from my website… I mean it should not be seen also a sidebar or anywhere.

I thought maybe ı can set title and linkTitle as blank as below in else part but not sure that its a proper solution or not.ıf it is how can I do that or what is the proper way of doing this ?

```
title: ""

linkTitle: ""

```

**baseof.html**

```
    {{ if not .Site.Params.ui.breadcrumb_disable }}{{ partial "breadcrumb.html" . }}{{ end }}
    {{- if .Params.audience }}
      {{- if in .Site.Params.audience (.Params.audience) }}
       {{ block "main" . }}{{ end }}
      {{- else }}
        This page is only accessible for {{ .Params.audience }}
      {{- end }}
    {{- else }}
     {{ block "main" . }}{{ end }}
   {{- end }}

```

**frontendmatter**

* * *

```
---

title: "API Management"

linkTitle: "API Management"

weight: 1

audience: "dealers"

description: >

```

—

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/2X/f/f5b5d84617cbcc8ce96f9721c56ad41c0649f16d.png)

Regards,  
Semih

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 4, 2020, 7:48am UTC](https://discourse.gohugo.io/t/display-hide-page/29793/2 "2020-12-04T07:48:57Z")

</div>

Have a look at the Build Options configuration:

> **[Build Options](https://gohugo.io/content-management/build-options/#readout)**
>
> Build options help define how Hugo must treat a given page when building the site.

---

<div class="post-metadata">

**Author:** ![Semih\_Ural](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/semih_ural/32/12799_2.png) [@Semih\_Ural](https://discourse.gohugo.io/u/Semih_Ural)\
**Post date:** [December 4, 2020, 7:58am UTC](https://discourse.gohugo.io/t/display-hide-page/29793/3 "2020-12-04T07:58:06Z")

</div>

But ı would like to do this according to parameter not always or not never…

Here is the sidebar.html by the way

```
{{ $shouldDelayActive := ge (len .Site.Pages) 2000 }}
<div id="td-sidebar-menu" class="td-sidebar__inner{{ if $shouldDelayActive }} d-none{{ end }}">
  {{ if not .Site.Params.ui.sidebar_search_disable }}
  <form class="td-sidebar__search d-flex align-items-center">
    {{ partial "search-input.html" . }}
    <button class="btn btn-link td-sidebar__toggle d-md-none p-0 ml-3 fas fa-bars" type="button" data-toggle="collapse" data-target="#td-section-nav" aria-controls="td-docs-nav" aria-expanded="false" aria-label="Toggle section navigation">
    </button>
  </form>
  {{ end }}
  <nav class="collapse td-sidebar-nav pt-2 pl-4" id="td-section-nav">
    {{ if (gt (len .Site.Home.Translations) 0) }}
    <div class="nav-item dropdown d-block d-lg-none">
      {{ partial "navbar-lang-selector.html" . }}
    </div>
    {{ end }}
    {{ template "section-tree-nav-section" (dict "page" . "section" .FirstSection "delayActive" $shouldDelayActive) }}
  </nav>
</div>
{{ define "section-tree-nav-section" }}
{{ $s := .section }}
{{ $p := .page }}
{{ $shouldDelayActive := .delayActive }}
{{ $active := eq $p.CurrentSection $s }}
{{ $show := or (and (not $p.Site.Params.ui.sidebar_menu_compact) ($p.IsAncestor $s)) ($p.IsDescendant $s) }}
{{ $sid := $s.RelPermalink | anchorize }}
<ul class="td-sidebar-nav__section pr-md-3">
  <li class="td-sidebar-nav__section-title">
    <a href="{{ $s.RelPermalink }}" class="align-left pl-0 pr-2{{ if not $show }} collapsed{{ end }}{{ if $active}} active{{ end }} td-sidebar-link td-sidebar-link__section">{{ $s.LinkTitle }}</a>
  </li>
  <ul>
    <li class="collapse {{ if $show }}show{{ end }}" id="{{ $sid }}">
      {{ $pages := where (union $s.Pages $s.Sections).ByWeight ".Params.toc_hide" "!=" true }}
      {{ $pages := $pages | first 50 }}
      {{ range $pages }}
      {{ if .IsPage }}
      {{ $mid := printf "m-%s" (.RelPermalink | anchorize) }}
      {{ $active := eq . $p }}
      <a class="td-sidebar-link td-sidebar-link__page {{ if and (not $shouldDelayActive) $active }} active{{ end }}" id="{{ $mid }}" href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
      {{ else }}
      {{ template "section-tree-nav-section" (dict "page" $p "section" .) }}
      {{ end }}
      {{ end }}
    </li>
  </ul>
</ul>
{{ end }}
```

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 4, 2020, 8:07am UTC](https://discourse.gohugo.io/t/display-hide-page/29793/4 "2020-12-04T08:07:26Z")

</div>

> [@Semih\_Ural](#):
>
> But ı would like to do this according to parameter not always or not never…

You can also use the Build options as needed or remove them from a content file once you need it re-listed. Anyway Build Options offer the cleanest way to partially hide a page in a Hugo project.

I’m sure others can help you with what you want.

---

<div class="post-metadata">

**Author:** ![Semih\_Ural](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/semih_ural/32/12799_2.png) [@Semih\_Ural](https://discourse.gohugo.io/u/Semih_Ural)\
**Post date:** [December 4, 2020, 10:17am UTC](https://discourse.gohugo.io/t/display-hide-page/29793/5 "2020-12-04T10:17:37Z")

</div>

How should I pass the params to build ?

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 4, 2020, 10:27am UTC](https://discourse.gohugo.io/t/display-hide-page/29793/6 "2020-12-04T10:27:08Z")

</div>

There are no `build options` CLI flags to pass during site generation if that is what you’re asking.

The Docs offer concise use cases for Build Options:

> **[Build Options](https://gohugo.io/content-management/build-options/#illustrative-use-cases)**
>
> Build options help define how Hugo must treat a given page when building the site.

---

<div class="post-metadata">

**Author:** ![Semih\_Ural](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/semih_ural/32/12799_2.png) [@Semih\_Ural](https://discourse.gohugo.io/u/Semih_Ural)\
**Post date:** [December 4, 2020, 10:29am UTC](https://discourse.gohugo.io/t/display-hide-page/29793/7 "2020-12-04T10:29:15Z")

</div>

Yeap that was what I tried to ask… So cant I add a same params to sidebar.html ı tried but it did not work though it is completely remove the sidebar where I would like to hide only the related title and linktitle so then it was hidden completely from the page

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 4, 2020, 10:38am UTC](https://discourse.gohugo.io/t/display-hide-page/29793/8 "2020-12-04T10:38:59Z")

</div>

> [@Semih\_Ural](#):
>
> So cant I add a same params to sidebar.html ı tried but it did not work though it is completely remove the sidebar where I would like to hide only the related title and linktitle

You can do the above by using `with`

> Rebinds the context ( `.` ) within its scope and skips the block if the variable is absent or empty.

e.g.

```auto
{{ with .Param.foo }}
<--- sidebar page links --->
{{ end }}

```

OR

Filter the sidebar links with [`where`](https://gohugo.io/functions/where#readout)

e.g.

```auto
range where .Pages "Params.foo" "!=" "foo"

```

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 4, 2020, 10:50am UTC](https://discourse.gohugo.io/t/display-hide-page/29793/10 "2020-12-04T10:50:00Z")

</div>

I don’t know what kind of link you’re trying to hide. Is it for a regular page or a section list?

If it’s a regular page, I suppose that you could add a parameter in the relevant content file and then in `sidebar.html` try limiting the scope of `range $pages` with `where`.

---

<div class="post-metadata">

**Author:** ![Semih\_Ural](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/semih_ural/32/12799_2.png) [@Semih\_Ural](https://discourse.gohugo.io/u/Semih_Ural)\
**Post date:** [December 4, 2020, 10:59am UTC](https://discourse.gohugo.io/t/display-hide-page/29793/11 "2020-12-04T10:59:58Z")

</div>

So at the present, if I set audience parameter as below, and if I build my webpage via`> hugo server -e dealers` or without setting audience parameters the content should be seen.

But if the webpage build for employees lets say then it should be hidden completely. so far I can do that somehow but not able hidden the complete page or content from the my site.

So somehow, I need to this logic for sidebar as well but I am struggling to implement this.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/2X/8/83a97ae1658a10ebab36007767f860ed6a3a860b.png)

```
---

title: "API Management"

linkTitle: "API Management"

weight: 1

audience: "dealers"

description: >

---

```

here is the sidebar-tree.html

```
{{ $shouldDelayActive := ge (len .Site.Pages) 2000 }}
<div id="td-sidebar-menu" class="td-sidebar__inner{{ if $shouldDelayActive }} d-none{{ end }}">
  {{ if not .Site.Params.ui.sidebar_search_disable }}
  <form class="td-sidebar__search d-flex align-items-center">
    {{ partial "search-input.html" . }}
    <button class="btn btn-link td-sidebar__toggle d-md-none p-0 ml-3 fas fa-bars" type="button" data-toggle="collapse" data-target="#td-section-nav" aria-controls="td-docs-nav" aria-expanded="false" aria-label="Toggle section navigation">
    </button>
  </form>
  {{ end }}
  <nav class="collapse td-sidebar-nav pt-2 pl-4" id="td-section-nav">
    {{ if (gt (len .Site.Home.Translations) 0) }}
    <div class="nav-item dropdown d-block d-lg-none">
      {{ partial "navbar-lang-selector.html" . }}
    </div>
    {{ end }}
    {{ template "section-tree-nav-section" (dict "page" . "section" .FirstSection "delayActive" $shouldDelayActive) }}
  </nav>
</div>
{{ define "section-tree-nav-section" }}
{{ $s := .section }}
{{ $p := .page }}
{{ $shouldDelayActive := .delayActive }}
{{ $active := eq $p.CurrentSection $s }}
{{ $show := or (and (not $p.Site.Params.ui.sidebar_menu_compact) ($p.IsAncestor $s)) ($p.IsDescendant $s) }}
{{ $sid := $s.RelPermalink | anchorize }}
<ul class="td-sidebar-nav__section pr-md-3">
  <li class="td-sidebar-nav__section-title">
    <a href="{{ $s.RelPermalink }}" class="align-left pl-0 pr-2{{ if not $show }} collapsed{{ end }}{{ if $active}} active{{ end }} td-sidebar-link td-sidebar-link__section">{{ $s.LinkTitle }}</a>
  </li>
  <ul>
    <li class="collapse {{ if $show }}show{{ end }}" id="{{ $sid }}">
      {{ $pages := where (union $s.Pages $s.Sections).ByWeight ".Params.toc_hide" "!=" true }}
      {{ $pages := $pages | first 50 }}
      {{ range $pages }}
      {{ if .IsPage }}
      {{ $mid := printf "m-%s" (.RelPermalink | anchorize) }}
      {{ $active := eq . $p }}
      <a class="td-sidebar-link td-sidebar-link__page {{ if and (not $shouldDelayActive) $active }} active{{ end }}" id="{{ $mid }}" href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
      {{ else }}
      {{ template "section-tree-nav-section" (dict "page" $p "section" .) }}
      {{ end }}
      {{ end }}
    </li>
  </ul>
</ul>
{{ end }}

```

here is the sidebar.html

```
{{/* The "active" toggle here may delay rendering, so we only cache this side bar menu for bigger sites. */}}
{{ $shouldCache := ge (len .Site.Pages) 2000 }}
{{ if $shouldCache }}
{{ $mid := printf "m-%s" (.RelPermalink | anchorize) }}
<script>
$(function() {
$("#td-sidebar-menu #{{ $mid }}").toggleClass("active");
$("#td-sidebar-menu").toggleClass("d-none");
});
</script>
{{ partialCached "sidebar-tree.html" . .CurrentSection.RelPermalink }}
{{ else }}
{{ partial "sidebar-tree.html" . }}
{{ end }}
```

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 4, 2020, 11:21am UTC](https://discourse.gohugo.io/t/display-hide-page/29793/12 "2020-12-04T11:21:12Z")

</div>

> [@Semih\_Ural](#):
>
> So at the present, if I set audience parameter as below, and if I build my webpage via `> hugo server -e dealers` or without setting audience parameters the content should be seen.

Well… since you are using Environment Variables to generate different versions of the project you can use the `.Hugo.Environment` variable in the templates to conditionally display/hide the relevant sidebar links for the two different versions of the site.

For example

```auto
{{- if eq .Hugo.Environment "dealers" -}}
<-- sidebar links for dealers -->
{{- else -}}
<-- sidebar links for others -->
{{- end -}}

```

Also see:

[https://gohugo.io/variables/hugo/](https://gohugo.io/variables/hugo/)

---

<div class="post-metadata">

**Author:** ![Semih\_Ural](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/semih_ural/32/12799_2.png) [@Semih\_Ural](https://discourse.gohugo.io/u/Semih_Ural)\
**Post date:** [December 4, 2020, 11:37am UTC](https://discourse.gohugo.io/t/display-hide-page/29793/13 "2020-12-04T11:37:22Z")

</div>

Nope this is not ı want cause ı can not solve this if I have over 50 users…

So here is the part how the titles listed in sidebar.As you said before probably I need to use where clause for` {{ range $pages }}`

But ı am struggling how can ı the do the samething like I did in baseofhtml using params. The rules are,

- If there is no any audience parameter set in frontmatter list all the LinkTitle.

- If there is any audience parameter set, and if it is equal to one when building a site show the page if it is not equal then hidden the page.

> ```
> <ul>
> <li class="collapse {{ if $show }}show{{ end }}" id="{{ $sid }}">
> {{ $pages := where (union $s.Pages $s.Sections).ByWeight ".Params.toc_hide" "!=" true }}
> {{ $pages := $pages | first 50 }}
> {{ range $pages }}
> {{ if .IsPage }}
> {{ $mid := printf "m-%s" (.RelPermalink | anchorize) }}
> {{ $active := eq . $p }}
> <a class="td-sidebar-link td-sidebar-link__page {{ if and (not $shouldDelayActive) $active }} active{{ end }}" id="{{ $mid }}" href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
> {{ else }}
> {{ template "section-tree-nav-section" (dict "page" $p "section" .) }}
> {{ end }}
> {{ end }}
> </li>
> </ul>
> 
> ```

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 4, 2020, 11:47am UTC](https://discourse.gohugo.io/t/display-hide-page/29793/14 "2020-12-04T11:47:00Z")

</div>

> [@Semih\_Ural](#):
>
> - If there is no any audience parameter set in frontmatter list all the LinkTitle.
> - If there is any audience parameter set, and if it is equal to one when building a site show the page if it is not equal then hidden the page.

The above can be done dynamically.

```auto
<! -- store the audience parameter in a variable -->
{{ $audience := .Params.audience }}
<! -- then check if the audience parameter is set in a content file -->
{{ with $audience }}
<! -- check if the audience parameter matches the environment variable -->
{{ if eq .Hugo.Environment $audience }}
<! -- show the page -->
{{ else }}
<! -- hide the page -->
{{ end }}
{{ else }}
<! -- list all .LinkTitle since there is no audience parameter set -->
{{ end }}

```

The above should meet your stated requirements, more or less.  
Anyway you should get how conditional logic works in Hugo Templates.

---

<div class="post-metadata">

**Author:** ![Semih\_Ural](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/semih_ural/32/12799_2.png) [@Semih\_Ural](https://discourse.gohugo.io/u/Semih_Ural)\
**Post date:** [December 4, 2020, 11:52am UTC](https://discourse.gohugo.io/t/display-hide-page/29793/15 "2020-12-04T11:52:36Z")

</div>

ı could not explain the case really I feel (( I can able to hide or display the content but can hide the linktitle in side bar and I could not get how should I use the above code inside sidebar.html.

Let me ask another way… Can I able to title and Linktitle in frontmatter inside else section ? What ı mean instead of using this, `This page is only accessible for {{ .Params.audience }}`, if I can able to set the title and linkTitle like as below in else section that I will able to solve my issue i believe.

Can I override them as below ?

```
title: ""
linkTitle: ""

```

–

```
        {{- if .Params.audience }}
          {{- if in .Site.Params.audience (.Params.audience) }}
           {{ block "main" . }}{{ end }}
          {{- else }}
            This page is only accessible for {{ .Params.audience }}
          {{- end }}
        {{- else }}
         {{ block "main" . }}{{ end }}
```

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 4, 2020, 12:01pm UTC](https://discourse.gohugo.io/t/display-hide-page/29793/16 "2020-12-04T12:01:07Z")

</div>

> [@Semih\_Ural](#):
>
> Can I able to title and Linktitle in frontmatter inside else section ?

No. You cannot set frontmatter parameters in content files with conditional logic, if that is what you’re asking.

Template logic can only be used within Hugo Archetypes and when these are invoked with the command `hugo new` then the generated frontmatter will honor whatever logic exists in the Archetype.

Anyway. I think that in this topic I’ve given you a fairly extensive introduction to conditional logic in Hugo/Go templates.

I cannot help further without seeing the project in question or at least a sample repository that follows the same structure with dummy content.

If you intend to provide one then in the README you need to specify precisely which page links should be displayed in the sidebar and under which conditions.

---

<div class="post-metadata">

**Author:** ![Semih\_Ural](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/semih_ural/32/12799_2.png) [@Semih\_Ural](https://discourse.gohugo.io/u/Semih_Ural)\
**Post date:** [December 4, 2020, 12:06pm UTC](https://discourse.gohugo.io/t/display-hide-page/29793/17 "2020-12-04T12:06:21Z")

</div>

It s a private repository but let me try to find a solution…ok last question,ı ve another idea. so right now , due to ı can able to hide the content, as you can see below image there is nothing to display but unfortunatelly API Management still seen in side bar. So can ı use **len** here… What I mean just display the titles here where the len is greater than 0 or some specific amount… maybe that wway, due to len is zero here ı can hide the title in side bar as well

```
  {{ $pages := where (union $s.Pages $s.Sections).ByWeight ".Params.toc_hide" "!=" true }}
  {{ $pages := $pages | first 50 }}
  {{ range $pages }}
  {{ if .IsPage }}

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/2X/e/ef8ae5c8eb3d81b501a53b5a165398129586c3c7.png)

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 4, 2020, 12:10pm UTC](https://discourse.gohugo.io/t/display-hide-page/29793/18 "2020-12-04T12:10:50Z")

</div>

> [@Semih\_Ural](#):
>
> So can ı use **len** here…

You can use `len` to check for the length of the `title` and `linkTitle` values.

---

<div class="post-metadata">

**Author:** ![Semih\_Ural](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/semih_ural/32/12799_2.png) [@Semih\_Ural](https://discourse.gohugo.io/u/Semih_Ural)\
**Post date:** [December 4, 2020, 12:15pm UTC](https://discourse.gohugo.io/t/display-hide-page/29793/19 "2020-12-04T12:15:30Z")

</div>

No I am actually asking add a where condition here` {{ range $pages }}` if the len of content greater than zero and it will display, if not it will hide probably

---

<div class="post-metadata">

**Author:** ![iaeiou](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/iaeiou/32/15332_2.png) [@iaeiou](https://discourse.gohugo.io/u/iaeiou)\
**Post date:** [May 21, 2021, 9:20pm UTC](https://discourse.gohugo.io/t/display-hide-page/29793/20 "2021-05-21T21:20:25Z")

</div>

Depending on the way you want to hide your pages, be sure to check the RSS feed and the sidemap.xml too
