This is a write-up of a talk I gave at the Gotham Go conference in 2018. It won’t be identical to the talk, but should cover the same topics and convey the same message. Whenever the videos from the conference are posted online I’ll also link to it from here. Slides from this talk can be found here. What is Gophercises? Gophercises is a free course I created that is composed of mini-exercises to help budding Gophers (Go developers) practice writing Go code and gain familiarity with different aspects of the language.
This four part series explores Go's template package, which can be used to render HTML or text. Topics covered include contextual encoding, actions, using functions in templates, and how to build a proper view layer for a web application.
Learn how to create a reusable view layer to simplify HTML rendering. This includes creating a shared layout, defining default templates that can be overridden, and including the same templates across various pages without putting all of the code into a single file.
Go's template package provides many useful built-in functions. Learn to use a few of the more common ones, as well as how to add custom fucntions to your templates so that you can add any functionality you need.
This article on Go templates explains how to use common actions like if/else and range to create more dynamic outputs. After that we examine how to create nested templates and use them to avoid code repition.
A brief intro on how to create your first template in Go, which will allow you to create dynamic HTML pages. After that we explore how the variables are encoded depending on their context.
Jon Calhoun is a full stack web developer who teaches about Go, web development, algorithms, and anything programming. If you haven't already, you should totally check out his Go courses.
Previously, Jon worked at several statups including co-founding EasyPost, a shipping API used by several fortune 500 companies. Prior to that Jon worked at Google, competed at world finals in programming competitions, and has been programming since he was a child.
©2024 Jonathan Calhoun. All rights reserved.