Everything I learned | Week 22| Encora/Nearsoft Academy

Gibran Herrera
2 min readSep 6, 2021

Hi everyone! πŸ€—

This week I also worked with the Gophercises and study more about BASH, I made progress creating new thought structures and learn more about how Go is a unique programming language. So, let’s dive in!

β€” β€” β€” πŸ₯ HTML Templates πŸ₯ β€” β€” β€”

I had the misconception that you need Javascript for creating a compelling front-end for any web application, it never crossed my mind that other programming languages offer the possibility to create interactive web pages. In this case, I learned about the html/template package which was pretty easy to use due that I only needed this single statement:

tmpl := template.Must(template.ParseFiles("Templates/story.html"))

The tmpl variable stores a pointer to a Template struct which stores the complete HTML and checks for the double curly braces to inject the data. In this case, I created an HTML Template like this:

<div id="Text">        
{{range .Story}}
<p style="font-size: large;">
{{.}}
</p>
{{end}}
</div>

Which creates a loop with the Story slice and shows off each of its elements. The interesting thing here is the usage of points to access each element, and if the element is not assigned into a specific variable, the point should be alone.

β€” β€” β€” β›° Final Thoughts β›° β€” β€” β€”

HTML templates are a new thing into my known tools and I’m excited about having an alternative to JavaScript, which is not my favorite language, and it opens new possibilities to ensure other design patterns such as the MVC.

Thank you for reading until here!

See you! πŸ‘‹πŸ½

--

--

Gibran Herrera

Software Engineer πŸ‘¨β€πŸ’» β€” Pythonist 🐍 β€” Linux lover 🐧 β€” Learning πŸ¦€πŸ‹