{{ $currentPage := . }}
{{ $currentVersion := (index (findRE "[^/]+.*?" .RelPermalink) 0) }}
<aside class="sidebar">

  <div class="sidebar-toggle" onclick="toggle_sidebar('sidebar-closed');return false;"><a href="#">&#59672;</a></div>

  <div class="search-and-nav-toggle">
    <div class="sidebar--search">
      <input  class="sidebar--search-field"
              id="algolia-search-input"
              type="text"
              accesskey="s"
              autocomplete="off"
              autocorrect="off"
              autocapitalize="off"
              spellcheck="false"
              dir="auto"
              placeholder="Search {{ $currentVersion }}">
    </div>
    <a id="contents-toggle-btn" href="#">
      <span class="toggle-hamburger"></span>
    </a>
  </div>

  <ul id="nav-tree">

  {{ $menuID := replaceRE "[.]" "_" $currentVersion }}

  {{ range (index .Site.Menus $menuID) }}
    <!-- Nested Navigation -->
    <li class="nav-category {{ if eq $currentPage.URL .URL }}active{{end}}">
      {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
      <a href="{{ .URL }}">{{ .Name }}</a>
      {{ if .HasChildren }}
        <ul class="children {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}">
        {{ range .Children }}
          <li class="nav-item {{ if eq $currentPage.URL .URL }}active{{end}}">
            {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
            <a href="{{ .URL }}">{{ .Name }}</a>
            {{ if .HasChildren }}
              <ul class="children {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}">
              {{ range .Children }}
                <li class="nav-item {{ if eq $currentPage.URL .URL }}active{{end}}">
                  {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
                  <a href="{{ .URL }}">{{ .Name }}</a>
                  {{ if .HasChildren }}
                    <ul class="children {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}">
                    {{ range .Children }}
                      <li class="nav-item {{ if eq $currentPage.URL .URL }}active{{end}}">
                        {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
                        <a href="{{ .URL }}">{{ .Name }}</a>
                        {{ if .HasChildren }}
                          <ul class="children {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}">
                          {{ range .Children }}
                            <li class="nav-item {{ if eq $currentPage.URL .URL }}active{{end}}">
                              {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
                              <a href="{{ .URL }}">{{ .Name }}</a>
                              {{ if .HasChildren }}
                                <ul class="children {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}">
                                {{ range .Children }}
                                  <li class="nav-item {{ if eq $currentPage.URL .URL }}active{{end}}">
                                    {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
                                    <a href="{{ .URL }}">{{ .Name }}</a>

                                    <!-- Begin nested block -->
                                    {{ if .HasChildren }}
                                      <ul class="children {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}">
                                      {{ range .Children }}
                                        <li class="nav-item {{ if eq $currentPage.URL .URL }}active{{end}}">
                                          {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
                                          <a href="{{ .URL }}">{{ .Name }}</a>
                                          <!-- To add more nested layers, copy the nested block and paste it here -->
                                        </li>
                                      {{ end }}
                                      </ul>
                                    {{ end }}
                                    <!-- End nested block -->

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

  <!-- Reference Section -->
  {{ $refMenuID := print (replaceRE "[.]" "_" $currentVersion) "_ref" }}
  <h4 class="reference">Reference</h4>

  {{ range (index .Site.Menus $refMenuID) }}
    <!-- Nested Reference Navigation -->
    <li class="nav-category {{ if eq $currentPage.URL .URL }}active{{end}}">
      {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
      <a href="{{ .URL }}">{{ .Name }}</a>
      {{ if .HasChildren }}
        <ul class="children {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}">
        {{ range .Children }}
          <li class="nav-item {{ if eq $currentPage.URL .URL }}active{{end}}">
            {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
            <a href="{{ .URL }}">{{ .Name }}</a>
            {{ if .HasChildren }}
              <ul class="children {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}">
              {{ range .Children }}
                <li class="nav-item {{ if eq $currentPage.URL .URL }}active{{end}}">
                  {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
                  <a href="{{ .URL }}">{{ .Name }}</a>
                  {{ if .HasChildren }}
                    <ul class="children {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}">
                    {{ range .Children }}
                      <li class="nav-item {{ if eq $currentPage.URL .URL }}active{{end}}">
                        {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
                        <a href="{{ .URL }}">{{ .Name }}</a>
                        {{ if .HasChildren }}
                          <ul class="children {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}">
                          {{ range .Children }}
                            <li class="nav-item {{ if eq $currentPage.URL .URL }}active{{end}}">
                              {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
                              <a href="{{ .URL }}">{{ .Name }}</a>
                              {{ if .HasChildren }}
                                <ul class="children {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}">
                                {{ range .Children }}
                                  <li class="nav-item {{ if eq $currentPage.URL .URL }}active{{end}}">
                                    {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
                                    <a href="{{ .URL }}">{{ .Name }}</a>

                                    <!-- Begin nested block -->
                                    {{ if .HasChildren }}
                                      <ul class="children {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}">
                                      {{ range .Children }}
                                        <li class="nav-item {{ if eq $currentPage.URL .URL }}active{{end}}">
                                          {{ if .HasChildren }}<a href="#" class="children-toggle {{ if or ($currentPage.IsMenuCurrent .Menu .) ($currentPage.HasMenuCurrent .Menu .) }}open{{end}}"></a>{{ end }}
                                          <a href="{{ .URL }}">{{ .Name }}</a>
                                          <!-- To add more nested layers, copy the nested block and paste it here -->
                                        </li>
                                      {{ end }}
                                      </ul>
                                    {{ end }}
                                    <!-- End nested block -->

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


  </ul>
</aside>
