Skip to content

Instantly share code, notes, and snippets.

@suhodolskiy
Created April 22, 2022 22:12
Show Gist options
  • Save suhodolskiy/992a195c83d36df6c0285654224ec377 to your computer and use it in GitHub Desktop.
Save suhodolskiy/992a195c83d36df6c0285654224ec377 to your computer and use it in GitHub Desktop.
Golang html/template
<ul>
<li>
Level 1
<ul>
<li>
Level 2
<ul>
<li>
Level 2
<ul>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
{{ template "children" .Children }}
{{ define "children" }}
<ul>
{{ range $item := . }}
<li>
{{ $item.Name }}
{{ template "children" $item.Children }}
</li>
{{ end }}
</ul>
{{ end }}
@suhodolskiy
Copy link
Author

Expected result:

<ul>
  <li>Level 1
    <ul>
      <li>Level 2
        <ul>
          <li>Level 2
            <ul>
            </ul>
          </li>
        </ul>
      </li>
    </ul>
  </li>
</ul>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment