block by joyrexus ff9be7a1c3769a84360f

nested templates in go

Full Screen

Example of nested templates.

Given this file layout …

.
├── server.go
└── templates
    ├── profiles.html
    └── layout.html

… you can run the server (go run server.go).

Running curl localhost:3000/users should then return …

<html>
  <head>
    <title>User Profiles</title>
  </head>
  <body>

  <h2>User Profiles</h2>

    <p>
      Jack has the following hobbies ...
      <ul>
        <li>snowboarding</li>
        <li>croquet</li>
      </ul>
    </p>

    <p>
      Jill has the following hobbies ...
      <ul>
        <li>knitting</li>
        <li>minecraft</li>
      </ul>
    </p>

  </body>
</html>

index.html

layout.html

profiles.html

server.go