In templating, we retrieve the posts that we have created by reading a file and convert them into an HTML file. We then serve them directly through the html.ResponseWriter.

template : template allows us to create dynamic strings, by inserting strings in a predefined place holders

go provides two template packages text/template html/template, use html/template when the output is html, it should be for generating html output safe from code injection

syntax for templates : https://pkg.go.dev/text/template

New:

func New(name [string](<https://pkg.go.dev/builtin#string>)) *[Template](<https://pkg.go.dev/text/template#Template>)

New allocates a new, undefined template with the given name

Parse:

func (t *[Template](<https://pkg.go.dev/text/template#Template>)) Parse(text [string](<https://pkg.go.dev/builtin#string>)) (*[Template](<https://pkg.go.dev/text/template#Template>), [error](<https://pkg.go.dev/builtin#error>))

Parse parses text as a template body for t. Named template definitions ({{define ...}} or {{block ...}} statements) in text define additional templates associated with t and are removed from the definition of t itself.

Execute:

func (t *[Template](<https://pkg.go.dev/text/template#Template>)) Execute(wr [io](<https://pkg.go.dev/io>).[Writer](<https://pkg.go.dev/io#Writer>), data [any](<https://pkg.go.dev/builtin#any>)) [error](<https://pkg.go.dev/builtin#error>)

Execute applies a parsed template to the specified data object, and writes the output to wr. If an error occurs executing the template or writing its output, execution stops, but partial results may already have been written to the output writer. A template may be executed safely in parallel, although if parallel executions share a Writer the output may be interleaved