go templates web

Building with Go Templates

Learn how to use Go templates for static site generation

Shou Arisaka
1 分で読める
2024年1月20日

Building with Go Templates

Go’s html/template package is powerful for building static sites. Here’s what makes it great:

Template Features

  • Safe by default - automatic HTML escaping
  • Template inheritance - base layouts and blocks
  • Custom functions - extend functionality
  • Conditional logic - if/else statements
  • Loops - range over collections

Example Template

{{range .Posts}}
<article>
    <h2>{{.Title}}</h2>
    <time>{{formatDate .Date}}</time>
    <p>{{truncate .Description 100}}</p>
</article>
{{end}}

This generator demonstrates these concepts in a practical way!

この記事をシェア

Shou Arisaka 2024年1月20日

🔗 リンクをコピー