job-board icon indicating copy to clipboard operation
job-board copied to clipboard

[DX] use nested templates and make header/footer/nav reusable

Open ghost opened this issue 3 years ago • 4 comments

all html views right now are copy-pasta and nothing is re-used, mostly the header and footer which can be plugged into a nested template and included in the view could simplify a lot the html and the overall maintenance of the views

https://pkg.go.dev/text/template#hdr-Nested_template_definitions

ghost avatar Feb 19 '22 19:02 ghost

for instance this would look like something like this

footer.html

{{define "footer"}}
  <syle type="text/css"> /** all css used only by the footer here **/</style>
  <script>/** all js used only by the footer here **/</script>
  <footer>
    <p>
      Golang Cafe ...
    </p>
  </footer>
{{end}}

landing.html

<html>
// ...
<body>
// ...
</div>
{{ template "footer" }}
</body>
</html>

Not sure if this exactly works like this but i can see that is possible to import and include other html files/templates in any Go html file template

https://stackoverflow.com/questions/33984147/golang-embed-html-from-file

ghost avatar Feb 20 '22 01:02 ghost

Potentially there are a lot of components that can be extracted into a re-usable template, some that come to mind:

  • footer
  • navbar
  • newsletter banner
  • newsletter box
  • company item in search (probably?)
  • job item in search (probably?)
  • developer item in search (probably?)

any of these will be a template file ending in .html and will include all the re-usable HTML/CSS/JS. Most of these will also have to take Go template variable as parameters. Like for instance the navbar will take active page so we can know how to underline a given nav/menu entry.

It will need a little research and trial so we can start just by extracting footer or nav

ghost avatar Feb 20 '22 01:02 ghost

for the approach please see discussion here https://github.com/golang-cafe/golang.cafe/pull/39#issuecomment-1046150761

Would be good to have different html template with css js html so that these get included/imported in the right locations (head for styles, end of body for javascript and wherever is needed for html)

ghost avatar Feb 20 '22 16:02 ghost

already started on this with newsletter template and others, could do the same for various re-usable components:

  • header
  • footer
  • etc

ghost avatar Apr 03 '23 18:04 ghost