Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Template Rendering with `ht | Go Programming Bootcamp lesson | BraveProgrammer
  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 20 of 60

·Go

Template Rendering with `html/template`

15 minutes

Course progress33%

HTML Templates

This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.

html/template auto‑escapes content, preventing XSS.

tmpl := template.Must(template.ParseFiles("index.html"))

type PageData struct { Title string; Items []string }

 {
    data := PageData{Title: , Items: []{, , }}
    tmpl.Execute(w, data)
}
func handler(w http.ResponseWriter, r *http.Request)
"My Site"
string
"Go"
"Docker"
"K8s"

Template syntax basics

<h1>{{ .Title }}</h1>
<ul>
{{ range .Items }}
    <li>{{ . }}</li>
{{ end }}
</ul>

Info

Always use html/template (instead of text/template) for rendering user‑generated HTML.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from Go Programming BootcampBrowse activities
Previous lessonJSON Marshalling & UnmarshallingContinue to lesson 21Building a RESTful API – CRUD OperationsBack to Go Programming Bootcamp curriculum