Docsy Hide Title from Sidebar according to the parameter

In docsy, how can I hide the LinkTitle or Title from the sidebar ? What I mean, I added some params as below for baseof.html to display/hide the contents according to the params. But instead of display This page is only accessible for I would like to completely hide the page and to do that ı need to hide it from the sidebar. I just check the sidebar-tree.html but somehow I could not able to do that… How can I achieve this ?

This is how the page look like if the audience is not equal the parameter when I build my side…For instance, if I build the site via hugo server -D -e employees then page needs to be hide , if it equals the one that I specified in Front Matter or if there is no any audience specified then page and title should be display in site

title: “API Management”
linkTitle: “API Management”
weight: 1
audience: “dealers”
description: >

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 }}

sidebar-tree.html
{{ 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 }}

It looks like the theme has no parameter for that. I would ask their support if they would be able to use newly added params feature in 0.79.0 for menus.

Having said that: If SECTIONS are what is to be hidden I would create two different deploy scripts with the one for general public doing a rm -rf after creating the site to delete unwanted or use disableKinds in the config to not create them in the first place.

That works for sections (disablekinds) or any arbitrary page (rm -rf in a post-script)

@davidsneighbour I am not sure whether if I can explain my requirement properly or not…

If you checked the baseof.html, I added an if statement to display or hide contents and it works… But as you can see the screenshot, even if content is empty( Just type this page accessible for dealers for testing) the header of related content(API Management) still display in sidebar where it has to be hide also for our requirement.

So, frankly I could not able to find a way to hide this using same condition that I used like for baseof.html. Thus, I am looking for a way to use same if condition for sidebar-tree.html.

It will be the same in the sidebar template (I think, I don’t know your other layout files and it could be, that the dot is not the page object at this point):

{{- if .Params.audience }}
  {{- if in .Site.Params.audience (.Params.audience) }}
    show link
  {{- else }}
    don't show link
  {{- end }}
{{- else }}
  show link
{{ end }}

So the sidebar might be the following code (not tested, there were two </ul> so code might be missing with a range that we need):

<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 }}
      <!-- pages is now all our pages -->

      {{ range $pages }}
        <!-- the dot (.) is now one single page with params -->

{{- if .Params.audience }}
  {{- if in .Site.Params.audience (.Params.audience) }}
    
<!-- I ignored this code and assume, that it creates the link you want to show -->
      {{ 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 of ignoring -->

  {{- else }}
<!--    don't show link, meaning remove the else above and this line -->
  {{- end }}
{{- else }}

<!-- I ignored this code and assume, that it creates the link you want to show -->
      {{ 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 of ignoring -->


{{ end }}



<!-- and that's the end of the range -->

      {{ end }}
    </li>
  </ul>
{{ end }}

Because you basically show the link twice you should put all that I ignored into one single partial and them import that with {{ partial "navitem" . }} (if you put it into layouts/partials/navitem.html)

@davidsneighbour this is what ı am looking for and it worked as I expected… Appreciate for your supports…

The only issue when I search someting in the page , it can be also seen in search output. Do you think is there anyway to filter this ?

not really, because I don’t know your search engine. In the end, it might end up the same way with the double if or else print thingy in my last answer, this time in your search engine creation layout.

I have a distinct feeling there should be a “global” way to sort ALL your content but I am very afraid that’s a pandora’s box to be opened.

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